Search for files that conflict or are locally edited during git merge

Reference Information. I am working on a prefix tool. As a developer, it can be quite frustrating to pull out another developer branch and make the pre-commit hook loudly complain about files that I haven't even touched.

What I would like to do in my implementation is that in the case of merge-commit, freezes of files that were either conflicting or manually edited by me locally during the merge conflict are triggered.

What I have tried so far:

  • git diff --staged- This is what the current solution makes and is not correct, because it contains all the files, including those that merge cleanly.
  • git diff MERGE_HEAD - This is pretty close, but if the branch with which I am merging branches from the master after that, it contains all the changes from the master that I have not yet merged.
  • .git/MERGE_MSGcontains a list of conflicting files. This seems like a good starting point, but does not contain locally edited files.
  • After fixing , it git show --name-onlygets exactly what I want. But it's too late (I implement pre-commit in the end: D)
+4
source share
2 answers

, git diff -m. , . git diff -m child parent1 parent2 ...., , , . parent1, [ +-] .. , . git write-tree ; .

, , - , , , , , - .

$ CURRENTLY_ADDED=`git write-tree`
$ git diff -m $CURRENTLY_ADDED HEAD MERGE_HEAD
diff --cc README
index 2ef4a65,8e2e466..be3d46e
--- a/README
+++ b/README
@@@ -1,10 -1,5 +1,10 @@@
 -deleted only in <theirs>
 +added only in <theirs>
- deleted only in <ours>
+ added only in <ours>
--deleted during merge
++added during merge
+2

git add , . , , :

cp .git/index .git/preserved-merge-index

GIT_INDEX_FILE=.git/preserved-merge-index git ls-files --unmerged

GIT_INDEX_FILE=.git/preserved-merge-index git diff-files --name-only

, .

. , , ,

GIT_INDEX_FILE=.git/preserved-merge-index git diff-index --name-only `git write-tree`
+4

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


All Articles