Git patch ignoring C ++ diffs space

The only thing that worries me is the C ++ file. (Don't worry about binaries, text, etc ... you can assume that all this is C ++ _ code).

I have these branches:

* dev master 

Now I can create a new branch "magic", where the branch magic is equivalent to "dev" (generated by C ++ code), but minimizes useless differences in whiteline (for example, insertion of additional translation lines) from master.

Is it possible?

Thanks!

+4
source share
3 answers

Your question is not entirely clear to me. I think you want the new branch to contain a number of commits that are "equivalent" to those in dev but do not contain unnecessary changes to spaces.

The easiest way to do this is git rebase --interactive . This allows you to manually edit a series of commits. You can get the hash of the first ("root") commit with git rev-list HEAD | tail -n 1 git rev-list HEAD | tail -n 1 . If you want to edit the first commit as well, it's harder, but there is an SO answer for that.

 git checkout dev git checkout -b magic git rebase --interactive $(git rev-list HEAD | tail -n 1) 

This calls the editor in the commit list in direct chronological order. You change the selection for editing on the commits you want to change. git then pauses until each of these commits is processed, allowing you to change it with git commit --amend , and then continue rebase with git rebase --continue . Of course, you can run the script to clean the files, and not to edit them manually. If you want to do this depending on the differences from the previous commit, you will need to use something like git cat-file blob HEAD^:filename to retrieve the previous version or use git diff HEAD^ filename .

If you want to automate the whole process, you can use the git filter-branch --tree-filter script . See the man page for git-filter-branch for more details.

If you want future commits to not contain errors in the form of spaces, you can configure hook hooks to prevent them.

Once you are happy with the new branch magic, you can use it to replace dev:

 git branch -m dev dev-old git branch -m magic dev 

However, note that this can cause problems for people who already have a copy of dev in their own repositories. Then it would be better to merge.

+1
source

git diff --ignore-space-change ...

0
source

You can try setting up a post-merge hook that will:

  • just do anything if the current branch is magical
  • delete all whitelines from * .cpp files
  • make a new commit (since the post-merge hook cannot directly affect the result of git merge )
0
source

Source: https://habr.com/ru/post/1309639/


All Articles