开发者

In a git merge, how do you just replace your version with the version git says there is a conflict with?

开发者 https://www.devze.com 2023-01-12 16:50 出处:网络
I have two files: 开发者_JS百科A and B. If I have been working on A and a partner is working on B, I want to merge files A and B. B is already committed. Let\'s say my partner already made the changes

I have two files: 开发者_JS百科A and B. If I have been working on A and a partner is working on B, I want to merge files A and B. B is already committed. Let's say my partner already made the changes I was working on, so I just want to replace my A file with their B file - no merge needed. How do I resolve the conflict with git?

Thanks!


If their is a conflict during a merging operation (merge, cherry-pick, rebase, etc...) you can resolve conflict by picking one side of the changes by doing :

git checkout --ours <path> (this will choose the local changes)

or

git checkout --theirs <path> (this will choose the remote changes)

then finishing resolving the conflict as usual with:

git add <path>

then commit with:

git commit


Let's say both you and your partner modified the same file, and is committed to each respective repository.

git pull                             # fetch/merge partners changes
# merge fails, conflict
git checkout origin FILE_TO_REPLACE  # replace changes with partners ver
git commit                           # finish merge
0

精彩评论

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