开发者

Accept all merge conflicts in git

开发者 https://www.devze.com 2022-12-29 22:14 出处:网络
I\'m trying to do a merge and there\'s a bunch of conflicts. It\'s all generated files so what I want to do is basically s开发者_高级运维ay \"ignore all merge conflicts, and check everything in from m

I'm trying to do a merge and there's a bunch of conflicts. It's all generated files so what I want to do is basically s开发者_高级运维ay "ignore all merge conflicts, and check everything in from my own repo".

I've tried

git checkout . --ours
git add -A
git com -a

It gives me an error though because there are still files in the "unmerged paths" bucket. How do I handle this?

Thanks!


Git commands are very wary of hiding conflicts - you pretty much have to explicitly check in a conflicted file to let it know that it's fixed. It does seem odd that there's not a -f style option for git add to let it know you really mean it, but here's an alias that I have which will help:

add-unmerged = \
    "!f() { git ls-files --unmerged | cut -f2 | sort -u ; }; git add `f`"

Bonus tip: if you change "git add" to $EDITOR, you now have edit-unmerged, for editing all the conflicted files!


Use a custom merge driver:
you can declare that driver in a .gitattributes located in the right directory (the one with the generated files whose merge you do not want to deal with)

* merge=keepMine

(you can specify a more precise pattern to isolate the exact files concerned with that custom merge)

with the config:

[merge "keepMine"]
        name = always keep mine during merge
        driver = keepMine.sh %O %A %B

See "How do I tell git to always select my local version for conflicted merges on a specific file?" for a complete example.


No native git support, but you can try the following hack:

git status | grep "both modified:" | awk '{print $NF}' | xargs git add

To be safe, run the command without xargs first to inspect the files to be added.


For this case, using regex will help for staging.

After resolution of conflict, to add files that are in unmerged paths, you can use common identifier of the files.

For example, if few text files and xml files need to be committed, extensions on files are .txt and .xml, stage the files using the below command.

git add *.txt *.xml

Note: this will add all the .txt and .xml files in the repository, even those which are untracked files.

0

精彩评论

暂无评论...
验证码 换一张
取 消