Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can keep master files after merge conflict in git

I fall in to this situation many times

1. I work on master branch and make some commits
2. Then i use git pull
3. Then i get auto merge fail , conflicting changes

Now suppose there were 5 files which were conflicting. I want to know

1. How can i overwrite those conflicting files with my files on my commit
2. How can i overwrite those with chnages from master

after i do git pull

like image 962
user191542 Avatar asked Dec 03 '13 06:12

user191542


People also ask

What do I do after fixing merge conflicts?

When you fix your conflicted files and you are ready to merge, all you have to do is run git add and git commit to generate the merge commit. Once the commit was made , git push the changes to the branch. Reference article: Git merge.

What happens if you get a conflict during a merge?

Merge conflicts happen when you merge branches that have competing commits, and Git needs your help to decide which changes to incorporate in the final merge. Git can often resolve differences between branches and merge them automatically.


1 Answers

You can use

git checkout --theirs -- path/to/file.txt

to checkout what you fetched

git checkout --ours -- path/to/other/file.txt

to checkout what you had originally.

git diff --name-only --diff-filter=U | xargs git checkout --ours -- 

to use your version of all conflicted files.

like image 60
Adam Dymitruk Avatar answered Oct 04 '22 20:10

Adam Dymitruk