git: change styling (whitespace) without changing ownership/blame?

两盒软妹~` 提交于 2019-11-27 07:12:40

In an ideal world there would be some way to rewrite history to look like the violations were never introduced

git filter-branch does precisely that.

http://git-scm.com/docs/git-filter-branch

This has the same issues as all history rewriting commands do, as it essentially invalidates all cloned repositories.

Mario Zaizar

If you are trying to get a Root Cause issue using blame, don't forget use the -w flag to ignore all the white-spaces or indentation changes. So you'll get the last real change to the code, instead just an indentation, or removing trailing spaces.

git blame -w app/to/file.rb

or you can just use, git slap command..

git config alias.slap "blame -w";
git slap app/path/to/file.rb

having same results :D

Building on Mario's answer, I would suggest git shame as a global git-alias:

git config --global alias.shame 'blame -w -M'

...and use it instead of git-blame:

git shame path/to/file

To explain:
- -w Ignores whitespace changes, so not to blame someone who re-indented the code
- -M Detects lines that were moved or copied, and blames the original author

I did a pull request to the TextMate git Bundle, to set this "-w" parameter by default for the "Browse Annoted File (Blame)" command. Thanks Mario Zaizar, you made my day.

diff --git a/Support/lib/git.rb b/Support/lib/git.rb
index 5e8de13..5192953 100644
--- a/Support/lib/git.rb
+++ b/Support/lib/git.rb
@@ -307,6 +307,9 @@ module SCM
       file = make_local_path(file_path)
       args = [file]
       args << revision unless revision.nil? || revision.empty?
+      # Ignore whitespace when comparing the parent's version and
+      # the child's to find where the lines came from.
+      args << '-w'
       output = command("annotate", *args)
       if output.match(/^fatal:/)
         puts output 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!