Git跟踪代码块在文件中移动/删除

时间:2015-11-12 21:44:50

标签: git git-log git-blame

我在// Calendar grid generation // $calendar-columns: 7; $calendar-gutter-width: $grid-gutter-width; // [converter] This is defined recursively in LESS, but Sass supports real loops @mixin make-calendar-columns() { $list: ''; $i: 1; $list: ".calendar-xs-#{$i}, .calendar-sm-#{$i}, .calendar-md-#{$i}, .calendar-lg-#{$i}"; @for $i from (1 + 1) through $calendar-columns { $list: "#{$list}, .calendar-xs-#{$i}, .calendar-sm-#{$i}, .calendar-md-#{$i}, .calendar-lg-#{$i}"; } #{$list} { position: relative; // Prevent columns from collapsing when empty min-height: 1px; // Inner gutter via padding padding-left: ($calendar-gutter-width / 2); padding-right: ($calendar-gutter-width / 2); } } // [converter] This is defined recursively in LESS, but Sass supports real loops @mixin float-calendar-columns($class) { $list: ''; $i: 1; $list: ".calendar-#{$class}-#{$i}"; @for $i from (1 + 1) through $calendar-columns { $list: "#{$list}, .calendar-#{$class}-#{$i}"; } #{$list} { float: left; } } @mixin calc-calendar-column($index, $class, $type) { @if ($type == width) and ($index > 0) { .calendar-#{$class}-#{$index} { width: percentage(($index / $calendar-columns)); } } @if ($type == push) and ($index > 0) { .calendar-#{$class}-push-#{$index} { left: percentage(($index / $calendar-columns)); } } @if ($type == push) and ($index == 0) { .calendar-#{$class}-push-0 { left: auto; } } @if ($type == pull) and ($index > 0) { .calendar-#{$class}-pull-#{$index} { right: percentage(($index / $calendar-columns)); } } @if ($type == pull) and ($index == 0) { .calendar-#{$class}-pull-0 { right: auto; } } @if ($type == offset) { .calendar-#{$class}-offset-#{$index} { margin-left: percentage(($index / $calendar-columns)); } } } // [converter] This is defined recursively in LESS, but Sass supports real loops @mixin loop-calendar-columns($calendar-columns, $class, $type) { @for $i from 0 through $calendar-columns { @include calc-calendar-column($i, $class, $type); } } // Create grid for specific class @mixin make-calendar($class) { @include float-calendar-columns($class); @include loop-calendar-columns($calendar-columns, $class, width); @include loop-calendar-columns($calendar-columns, $class, pull); @include loop-calendar-columns($calendar-columns, $class, push); @include loop-calendar-columns($calendar-columns, $class, offset); } // Row // // Rows contain and clear the floats of your columns. .row { @include make-row($calendar-gutter-width); } // Columns // // Common styles for small and large grid columns @include make-calendar-columns(); // Extra small grid // // Columns, offsets, pushes, and pulls for extra small devices like // smartphones. @include make-calendar(xs); // Small grid // // Columns, offsets, pushes, and pulls for the small device range, from phones // to tablets. @media (min-width: $screen-sm-min) { @include make-calendar(sm); } // Medium grid // // Columns, offsets, pushes, and pulls for the desktop device range. @media (min-width: $screen-md-min) { @include make-calendar(md); } // Large grid // // Columns, offsets, pushes, and pulls for the large desktop device range. @media (min-width: $screen-lg-min) { @include make-calendar(lg); } 上有一个旧提交md5hash,提交正文中有myfile.extension(不是提交标题/元数据)。

如何在SOME CHANGE提交SOME CHANGE的提交中生成HEAD已修改(不仅仅存在)的提交列表,而无需检查每个差异? (其中不幸的是,在目前的情况下很多。)

我尝试了md5hash,但这似乎找到了文件中git rev-list --all | xargs git grep 'SOME CHANGE'的所有提交。

SOME CHANGE似乎没用,因为线条已经改变并且git blame已移动。

3 个答案:

答案 0 :(得分:4)

我认为您正在寻找的答案是git --no-pager log --pretty="%H" -G"SOME CHANGE" -- myfile.extension

起初我想到了git log -S,但它只涵盖了添加/删除。 git log -G可能接近你想要的。在这里,您可以看到-S-G之间的差异,并且我还包括完整的提交历史记录,因此您可以查看未涵盖的内容。阅读提交消息,了解我在正文中所做的事情。

# git --no-pager log --oneline -S"SOME CHANGE"
12e24ed Remove text
9427ffc Add the text
# git --no-pager log --oneline -G"SOME CHANGE"
12e24ed Remove text
6a33653 Change other text on same line
ac09bbb Append other text to same line
484b447 Move the text two lines down
9427ffc Add the text
# git --no-pager log --oneline
12e24ed Remove text
9c7f7d5 Change text on adjacent line
6a33653 Change other text on same line
ac09bbb Append other text to same line
484b447 Move the text two lines down
377936f Add other text on adjacent line
9427ffc Add the text
1929648 Initial commit

只用哈希来获得它:

# git --no-pager log --pretty="%H" -G"SOME CHANGE"
12e24ed749e499bc2d8920c5d8a3ca98a6422e3f
6a336532210ca85dea86968c34cef516345b8ab4
ac09bbb5c95bbea65e7c99c730653d27f90397f4
484b4478e4cb16c839dac558f3e958683b428a64
9427ffc7dd60a3cfb1d9880083e6262faea0eefb

答案 1 :(得分:0)

这仍然需要稍微涉及结果,但这可能会让你更接近:

git rev-list --all | xargs git show | egrep '(^ ?[+-].*(SOME CHANGE)|^commit)' | egrep -B1 '^ ?[+-]' | uniq

这显示了每个提交的补丁,显示了它正在查看的内容,然后吐出匹配的代码行。比赛的相关比赛在比赛之上。

如果这是一种可行的方法,你可以进一步清理管道以清除结果。

答案 2 :(得分:0)

我认为你在寻找:

git log -S<string>
  

查找改变文件中指定字符串出现次数(即添加/删除)的差异。用于脚本编写者的使用。

     

当你正在寻找一个确切的代码块(比如一个结构体)时,它很有用,并且想要知道该块首次出现以来的历史:迭代地使用该特征来提供有趣的块。 preimage返回-S,并继续前进,直到你得到块的第一个版本。