어느 위원회에 이 방울이 있습니까?
블롭의 해시를 고려할 때 트리에 이 블롭이 있는 커밋 목록을 가져올 수 있는 방법이 있습니까?
다음 두 스크립트는 모두 Blob의 SHA1을 첫 번째 인수로 사용하며, 이후에는 이해할 수 있는 모든 인수를 선택적으로 사용합니다.예.--all
만 검색하지 합니다.-g
리필로그나 다른 원하는 것을 검색할 수 있습니다.
이것은 셸 스크립트로서 짧지만 달콤하지만 느립니다.
#!/bin/sh
obj_name="$1"
shift
git log "$@" --pretty=tformat:'%T %h %s' \
| while read tree commit subject ; do
if git ls-tree -r $tree | grep -q "$obj_name" ; then
echo $commit "$subject"
fi
done
그리고 Perl에서 최적화된 버전은 여전히 짧지만 훨씬 빠릅니다.
#!/usr/bin/perl
use 5.008;
use strict;
use Memoize;
my $obj_name;
sub check_tree {
my ( $tree ) = @_;
my @subtree;
{
open my $ls_tree, '-|', git => 'ls-tree' => $tree
or die "Couldn't open pipe to git-ls-tree: $!\n";
while ( <$ls_tree> ) {
/\A[0-7]{6} (\S+) (\S+)/
or die "unexpected git-ls-tree output";
return 1 if $2 eq $obj_name;
push @subtree, $2 if $1 eq 'tree';
}
}
check_tree( $_ ) && return 1 for @subtree;
return;
}
memoize 'check_tree';
die "usage: git-find-blob <blob> [<git-log arguments ...>]\n"
if not @ARGV;
my $obj_short = shift @ARGV;
$obj_name = do {
local $ENV{'OBJ_NAME'} = $obj_short;
`git rev-parse --verify \$OBJ_NAME`;
} or die "Couldn't parse $obj_short: $!\n";
chomp $obj_name;
open my $log, '-|', git => log => @ARGV, '--pretty=format:%T %h %s'
or die "Couldn't open pipe to git-log: $!\n";
while ( <$log> ) {
chomp;
my ( $tree, $commit, $subject ) = split " ", $_, 3;
print "$commit $subject\n" if check_tree( $tree );
}
인간에게 가장 유용한 명령은 아마도
git whatchanged --all --find-object=<blob hash>
이것은 가로로 보여줍니다.--all
경로와 함께 해당 해시가 있는 파일을 추가하거나 제거한 모든 커밋입니다.
git$ git whatchanged --all --find-object=b3bb59f06644
commit 8ef93124645f89c45c9ec3edd3b268b38154061a
⋮
diff: do not show submodule with untracked files as "-dirty"
⋮
:100644 100644 b3bb59f06644 8f6227c993a5 M submodule.c
commit 7091499bc0a9bccd81a1c864de7b5f87a366480e
⋮
Revert "submodules: fix of regression on fetching of non-init subsub-repo"
⋮
:100644 100644 eef5204e641e b3bb59f06644 M submodule.c
:git whatchanged
는 이미 출력 라인에 전후의 블롭 해시를 포함하고 있습니다.
안타깝게도 스크립트가 조금 느려서 최적화해야 했습니다.다행히도 저는 해시뿐만 아니라 파일의 경로도 가지고 있었습니다.
git log --all --pretty=format:%H -- <path> | xargs -I% sh -c "git ls-tree % -- <path> | grep -q <hash> && echo %"
이전 답변에서 언급한 것 외에도,git log
그리고.git diff
이제 "의 혜택도 누릴 수 있습니다.--find-object=<object-id>
이름이 지정된 개체와 관련된 변경 사항으로 소견을 제한하는 옵션입니다.
2)에 . Git 2.16.x/2.17 (2018년 1분기)입니다.
커밋 4d8c51a, 커밋 5e50525, 커밋 15af58c, 커밋 cf63051, 커밋 c1ddc46, 커밋 929ed70(2018년 1월 4일)을 Stefan Beller()stefanbeller
참조.
(주니오 C 하마노에 의해 합병 -- -- commit c0d75f0, 2018년 1월 23일)
diffcore
를 찾기 합니다.
때때로 사용자들은 객체의 해시를 제공받는데, 그들은 객체를 추가로 식별하기를 원합니다(예:가장 큰 방울을 찾으려면 verify-pack을 사용합니다. 하지만 이것들은 무엇입니까?또는 스택 오버플로 질문 "어떤 커밋에 이 블롭이 있습니까?")
연장하고 싶은 유혹이 있을 수 있습니다.
git-describe
블롭을 과▁that,▁to, bs게렇▁with▁blo▁such,▁also▁work.git describe <blob-id>
▁''▁gives'''로 설명합니다.<commit-ish>:<path>
'.
이것은 여기서 구현되었습니다. 응답의 수가 110개 이상인 것에서 알 수 있듯이, 이것은 올바르게 하기 어려운 것으로 나타났습니다.
올바른 선택을 하기 어려운 부분은 정확한 '커밋-ish'를 선택하는 것입니다. 그것은 블롭 또는 블롭을 제거한 블롭을 (다시) 도입한 커밋일 수 있습니다. 블롭은 다른 가지에 존재할 수 있습니다.Junio는 이 패치가 구현하는 이 문제를 해결하기 위한 다른 접근 방식을 암시했습니다.
치티를 .diff
표시된 내용으로 정보를 제한하기 위한 다른 플래그를 기계화합니다.
예:$ ./git log --oneline --find-object=v2.0.0:Makefile b2feb64 Revert the whole "ask curl-config" topic for now 47fbfde i18n: only extract comments marked with "TRANSLATORS:"
우리는 관찰합니다.
Makefile
동한대로에2.0
에 했습니다.v1.9.2-471-g47fbfded53
그고리로.v2.0.0-rc1-5-gb2feb6430b
.
이러한 커밋이 모두 v2.0.0 이전에 발생하는 이유는 이 새로운 메커니즘을 사용하여 찾을 수 없는 악의적인 병합 때문입니다.
marcono1234의 설명에서 언급한 것처럼 git log --all 옵션과 결합할 수 있습니다.
개체가 포함된 분기를 모를 때 유용할 수 있습니다.
블롭의 해시를 고려할 때 트리에 이 블롭이 있는 커밋 목록을 가져올 수 있는 방법이 있습니까?
Git 2.16 (Q1 2018)을 사용하면 나무를 더 깊게 파서 나무를 찾는 방법을 배웠기 때문에 좋은 해결책이 될 것입니다.<commit-ish>:<path>
그것은 주어진 블롭 물체를 가리킵니다.
커밋 644eb60, 커밋 4dbc59a, 커밋 cdaed0c, 커밋 c87b653, 커밋 5b6f9(2017년 11월 16일), 커밋 91904f5, 커밋 2da00(2017년 11월 2일)을 Stefan Beller()stefanbeller
참조.
(주니오 C 하마노에 의해 합병 -- -- 556de1a 커밋, 2017년 12월 28일)
방울을
builtin/describe.c
묘사합니다.때때로 사용자들은 객체의 해시를 제공받는데, 그들은 객체를 추가로 식별하기를 원합니다(예:사용하다
verify-pack
가장 큰 방울을 찾기 위해, 하지만 이것들은 무엇입니까?아니면 바로 이 질문입니다. "어떤 책임이 이 블롭을 가지고 있나요?"")커밋을 설명할 때 태그나 참조에 고정하려고 합니다. 태그나 참조가 커밋보다 개념적으로 더 높은 수준이기 때문입니다.그리고 정확히 일치하는 refort 태그가 없다면, 우리는 운이 없습니다.
그래서 우리는 커밋의 이름을 만들기 위해 휴리스틱을 사용합니다.이러한 이름은 모호하고, 고정할 태그나 참조가 다를 수 있으며, DAG에서 커밋에 정확하게 도달하기 위해 이동할 경로가 다를 수 있습니다.할 때,는 더 , 이은 블을설명때할더, 리다블설원튜다데플니입음의, .
(commit, deep/path)
관련된 나무 객체들이 다소 흥미롭지 않기 때문입니다.
동일한 BLOB가 여러 커밋에서 참조될 수 있는데, 어떤 커밋을 사용할지 어떻게 결정합니까?이 패치는 이에 대해 다소 단순한 접근 방식을 구현합니다.블롭에서 블롭이 발생하는 커밋까지 백포인터가 없으므로 사용 가능한 모든 팁에서 커밋 순서대로 블롭을 나열하고 블롭을 찾은 후 블롭을 나열한 첫 번째 커밋을 수행합니다.
예:
git describe --tags v0.99:Makefile conversion-901-g7672db20c2:Makefile
우리에게 말해줍니다.
Makefile
옛과같이에 있었던v0.99
커밋 7672db2에 도입되었습니다.걷기는 마지막으로 발생한 것이 아니라 방울의 도입을 보여주기 위해 역순으로 수행됩니다.
에서 도달할 수 하는 것 에, 단히커밋서도달수할대사태신설커는명하밋여을용하를그순신에최는있▁instead▁using,▁reachable대▁commit신ing▁the단는하설명커▁from▁a▁describ▁tag▁it밋▁of을▁most▁simply,.
git describe
실제로 사용 가능한 참조에 기초하여 사람이 읽을 수 있는 이름을 객체에 부여합니다.git describe <blob>
.만약 주어진 물체가 블롭을 언급한다면, 그것은 다음과 같이 설명될 것입니다.
<commit-ish>:<path>
블럽이 발견될 수 있도록<path>
에 시대에<commit-ish>
헤드의 리버스 리비전 워크에서 이 블롭이 발생하는 첫 번째 커밋을 설명합니다.
그러나:
벌레
트리 개체와 커밋을 가리키지 않는 태그 개체는 설명할 수 없습니다.
블롭을 설명할 때 블롭을 가리키는 경량 태그는 무시되지만 블롭은 여전히 다음과 같이 설명됩니다.<committ-ish>:<path>
가벼운 태그가 호의적임에도 불구하고.
저는 이것이 일반적으로 도움이 될 것이라고 생각했기 때문에, 그것을 하기 위해 작은 펄 스크립트를 작성했습니다.
#!/usr/bin/perl -w
use strict;
my @commits;
my %trees;
my $blob;
sub blob_in_tree {
my $tree = $_[0];
if (defined $trees{$tree}) {
return $trees{$tree};
}
my $r = 0;
open(my $f, "git cat-file -p $tree|") or die $!;
while (<$f>) {
if (/^\d+ blob (\w+)/ && $1 eq $blob) {
$r = 1;
} elsif (/^\d+ tree (\w+)/) {
$r = blob_in_tree($1);
}
last if $r;
}
close($f);
$trees{$tree} = $r;
return $r;
}
sub handle_commit {
my $commit = $_[0];
open(my $f, "git cat-file commit $commit|") or die $!;
my $tree = <$f>;
die unless $tree =~ /^tree (\w+)$/;
if (blob_in_tree($1)) {
print "$commit\n";
}
while (1) {
my $parent = <$f>;
last unless $parent =~ /^parent (\w+)$/;
push @commits, $1;
}
close($f);
}
if (!@ARGV) {
print STDERR "Usage: git-find-blob blob [head ...]\n";
exit 1;
}
$blob = $ARGV[0];
if (@ARGV > 1) {
foreach (@ARGV) {
handle_commit($_);
}
} else {
handle_commit("HEAD");
}
while (@commits) {
handle_commit(pop @commits);
}
오늘 저녁에 집에 도착하면 이것을 github에 올릴 것입니다.
업데이트: 누군가 이미 한 것 같습니다.같은 일반적인 아이디어를 사용하지만 세부 사항이 다르고 구현이 훨씬 짧다는 것입니다.어느 쪽이 더 빠를지는 모르겠지만 성능은 문제가 되지 않을 것입니다!
업데이트 2: 특히 대규모 저장소의 구현 속도가 훨씬 빠릅니다. ㅠㅠgit ls-tree -r
정말 아픕니다.
업데이트 3: 위의 성능 설명은 첫 번째 업데이트에서 위에 링크한 구현에 적용됩니다.아리스토텔레스의 구현은 나와 비슷한 성능을 발휘합니다.궁금한 분들을 위한 댓글에 더 자세한 내용.
원래 질문은 그것을 요구하지 않지만, 저는 blob이 언급되었는지를 확인하기 위해 준비 영역도 확인하는 것이 유용하다고 생각합니다.이렇게 하기 위해 원래 bash 스크립트를 수정했는데 저장소에서 손상된 BLOB를 참조하는 내용을 찾았습니다.
#!/bin/sh
obj_name="$1"
shift
git ls-files --stage \
| if grep -q "$obj_name"; then
echo Found in staging area. Run git ls-files --stage to see.
fi
git log "$@" --pretty=format:'%T %h %s' \
| while read tree commit subject ; do
if git ls-tree -r $tree | grep -q "$obj_name" ; then
echo $commit "$subject"
fi
done
8GB가 넘는 리포에 108,000개 이상의 수정사항이 있는 지정된 제한을 초과하는 모든 파일을 찾아야 했습니다.저는 이 완벽한 해결책에 도달하기 위해 제가 쓴 루비 스크립트와 함께 아리스토텔레스의 펄 스크립트를 각색했습니다.
첫째번.git gc
이렇게 하면 모든 개체가 팩 파일에 있는지 확인할 수 있습니다. 팩 파일이 아닌 개체는 검색하지 않습니다.
다음 이 스크립트를 실행하여 CUTOPE_SIZE 바이트 위의 모든 블롭을 찾습니다.large-blobs.log와 같은 파일로 출력 캡처
#!/usr/bin/env ruby
require 'log4r'
# The output of git verify-pack -v is:
# SHA1 type size size-in-packfile offset-in-packfile depth base-SHA1
#
#
GIT_PACKS_RELATIVE_PATH=File.join('.git', 'objects', 'pack', '*.pack')
# 10MB cutoff
CUTOFF_SIZE=1024*1024*10
#CUTOFF_SIZE=1024
begin
include Log4r
log = Logger.new 'git-find-large-objects'
log.level = INFO
log.outputters = Outputter.stdout
git_dir = %x[ git rev-parse --show-toplevel ].chomp
if git_dir.empty?
log.fatal "ERROR: must be run in a git repository"
exit 1
end
log.debug "Git Dir: '#{git_dir}'"
pack_files = Dir[File.join(git_dir, GIT_PACKS_RELATIVE_PATH)]
log.debug "Git Packs: #{pack_files.to_s}"
# For details on this IO, see http://stackoverflow.com/questions/1154846/continuously-read-from-stdout-of-external-process-in-ruby
#
# Short version is, git verify-pack flushes buffers only on line endings, so
# this works, if it didn't, then we could get partial lines and be sad.
types = {
:blob => 1,
:tree => 1,
:commit => 1,
}
total_count = 0
counted_objects = 0
large_objects = []
IO.popen("git verify-pack -v -- #{pack_files.join(" ")}") do |pipe|
pipe.each do |line|
# The output of git verify-pack -v is:
# SHA1 type size size-in-packfile offset-in-packfile depth base-SHA1
data = line.chomp.split(' ')
# types are blob, tree, or commit
# we ignore other lines by looking for that
next unless types[data[1].to_sym] == 1
log.info "INPUT_THREAD: Processing object #{data[0]} type #{data[1]} size #{data[2]}"
hash = {
:sha1 => data[0],
:type => data[1],
:size => data[2].to_i,
}
total_count += hash[:size]
counted_objects += 1
if hash[:size] > CUTOFF_SIZE
large_objects.push hash
end
end
end
log.info "Input complete"
log.info "Counted #{counted_objects} totalling #{total_count} bytes."
log.info "Sorting"
large_objects.sort! { |a,b| b[:size] <=> a[:size] }
log.info "Sorting complete"
large_objects.each do |obj|
log.info "#{obj[:sha1]} #{obj[:type]} #{obj[:size]}"
end
exit 0
end
그런 다음 파일을 편집하여 대기하지 않는 블롭과 맨 위에 있는 INPUT_THREAD 비트를 제거합니다.찾으려는 sha1에 대한 줄만 있으면 다음과 같은 스크립트를 실행합니다.
cat edited-large-files.log | cut -d' ' -f4 | xargs git-find-blob | tee large-file-paths.log
곳git-find-blob
스크립트는 아래와 같습니다.
#!/usr/bin/perl
# taken from: http://stackoverflow.com/questions/223678/which-commit-has-this-blob
# and modified by Carl Myers <cmyers@cmyers.org> to scan multiple blobs at once
# Also, modified to keep the discovered filenames
# vi: ft=perl
use 5.008;
use strict;
use Memoize;
use Data::Dumper;
my $BLOBS = {};
MAIN: {
memoize 'check_tree';
die "usage: git-find-blob <blob1> <blob2> ... -- [<git-log arguments ...>]\n"
if not @ARGV;
while ( @ARGV && $ARGV[0] ne '--' ) {
my $arg = $ARGV[0];
#print "Processing argument $arg\n";
open my $rev_parse, '-|', git => 'rev-parse' => '--verify', $arg or die "Couldn't open pipe to git-rev-parse: $!\n";
my $obj_name = <$rev_parse>;
close $rev_parse or die "Couldn't expand passed blob.\n";
chomp $obj_name;
#$obj_name eq $ARGV[0] or print "($ARGV[0] expands to $obj_name)\n";
print "($arg expands to $obj_name)\n";
$BLOBS->{$obj_name} = $arg;
shift @ARGV;
}
shift @ARGV; # drop the -- if present
#print "BLOBS: " . Dumper($BLOBS) . "\n";
foreach my $blob ( keys %{$BLOBS} ) {
#print "Printing results for blob $blob:\n";
open my $log, '-|', git => log => @ARGV, '--pretty=format:%T %h %s'
or die "Couldn't open pipe to git-log: $!\n";
while ( <$log> ) {
chomp;
my ( $tree, $commit, $subject ) = split " ", $_, 3;
#print "Checking tree $tree\n";
my $results = check_tree( $tree );
#print "RESULTS: " . Dumper($results);
if (%{$results}) {
print "$commit $subject\n";
foreach my $blob ( keys %{$results} ) {
print "\t" . (join ", ", @{$results->{$blob}}) . "\n";
}
}
}
}
}
sub check_tree {
my ( $tree ) = @_;
#print "Calculating hits for tree $tree\n";
my @subtree;
# results = { BLOB => [ FILENAME1 ] }
my $results = {};
{
open my $ls_tree, '-|', git => 'ls-tree' => $tree
or die "Couldn't open pipe to git-ls-tree: $!\n";
# example git ls-tree output:
# 100644 blob 15d408e386400ee58e8695417fbe0f858f3ed424 filaname.txt
while ( <$ls_tree> ) {
/\A[0-7]{6} (\S+) (\S+)\s+(.*)/
or die "unexpected git-ls-tree output";
#print "Scanning line '$_' tree $2 file $3\n";
foreach my $blob ( keys %{$BLOBS} ) {
if ( $2 eq $blob ) {
print "Found $blob in $tree:$3\n";
push @{$results->{$blob}}, $3;
}
}
push @subtree, [$2, $3] if $1 eq 'tree';
}
}
foreach my $st ( @subtree ) {
# $st->[0] is tree, $st->[1] is dirname
my $st_result = check_tree( $st->[0] );
foreach my $blob ( keys %{$st_result} ) {
foreach my $filename ( @{$st_result->{$blob}} ) {
my $path = $st->[1] . '/' . $filename;
#print "Generating subdir path $path\n";
push @{$results->{$blob}}, $path;
}
}
}
#print "Returning results for tree $tree: " . Dumper($results) . "\n\n";
return $results;
}
출력은 다음과 같습니다.
<hash prefix> <oneline log message>
path/to/file.txt
path/to/file2.txt
...
<hash prefix2> <oneline log msg...>
큰 됩니다.트리에 큰 파일이 포함된 모든 커밋이 나열됩니다.네가 만약grep
탭로시는줄제외고하을하작으,▁that고▁the,uniq
제거할 수 있는 모든 경로 목록을 필터링하거나 더 복잡한 작업을 수행할 수 있습니다.
다시 한 번 말씀드리지만, 이 프로세스는 108,000개의 커밋으로 10GB 레포에서 성공적으로 실행되었습니다.많은 수의 블롭에서 실행할 때 예상했던 것보다 훨씬 더 오래 걸렸지만, 10시간이 넘도록 메모리 비트가 작동하는지 확인해야 할 것입니다...
언급URL : https://stackoverflow.com/questions/223678/which-commit-has-this-blob
'programing' 카테고리의 다른 글
어떻게 RGB 이미지를 numpy 배열로 변환합니까? (0) | 2023.07.16 |
---|---|
총 행 수와 고유 행 수 간의 차이를 가져오기 위한 쿼리 (0) | 2023.07.16 |
웹 서버를 시작할 수 없음 (0) | 2023.07.16 |
프로그램의 단일 인스턴스만 실행 중인지 확인 (0) | 2023.07.16 |
mongoose를 사용하여 MongoDB에서 대량 업그레이드 (0) | 2023.07.16 |