Git commit that doesn't override original auth

2020-01-27 02:48发布

I've used a perl script to modify all tab characters in a php git repository and changed them all to 4 spaces.

$ find -iname \*.php -exec perl -pi -e "s/\t/    /g" {} \

I can commit this change with git commit, but it will mark me as the author of all changed lines inside git blame after this commit is made.

Is there any way to commit this massive change that doesn't mark me as the author of the changed lines, but retains the original author? That's a lot of history we don't really want to lose in our project.

Our purpose in replacing tabs with 4 spaces is not to make things appear different in git blame, but to follow proper PEAR coding standards. E.g. no tabs, use 4 spaces for indentation.

2条回答
贼婆χ
2楼-- · 2020-01-27 03:08

It isn't the responsibility of the commit command to decide how to treat whitespaces, but the responsibility of the blame command because it is blame which analyzes the differences between versions to get the author of each line. So searching for an option to ignore whitespace in blame:

The option -w is defined as: "Ignore whitespace when comparing the parent's version and the child's to find where the lines came from." http://kernel.org/pub/software/scm/git/docs/git-blame.html

查看更多
小情绪 Triste *
3楼-- · 2020-01-27 03:20

Thanks to wnoise on git: change styling (whitespace) without changing ownership/blame?, I came up with this to run an arbitrary filter on git history, so using this you could rewrite history to make it look like offending whitespace or other issues were never committed, leaving the original authors in tact but your code cleaned up: git filter-branch --tree-filter 'git diff-tree --name-only --diff-filter=AM -r --no-commit-id $GIT_COMMIT | php cleanup.php' HEAD

查看更多
登录 后发表回答