简体   繁体   中英

Git Merge and Changes, Safe Way to Deal

I am trying to merge a branch into the master. The branch I built on, called auths_images has the changes I want overridden in master . When I merge, I get a whole sleu of errors basically telling me...

CONFLICT (add/add): Merge conflict in file
Automatic merge failed; fix conflicts and then commit the result.

I KNOW auth_images is up to date with master , and has changes that will work with master . How do I get merge to work such that it uses the changes from the branch?

An add/add conflict means that since the base, both your current (HEAD) commit on your current branch, and the tip of the other branch, added a file with the same name. Git does not know how to deal with that. You must put the correct combined file into your work-tree and run git add on that path name.

If the two files were exactly the same, Git would not have a problem. Git would say to itself: Gosh, file somenewfile is totally new in branch auth_images and also totally new in master . But look at that, it's the same now in both branch tips! I can just use either one of them and all will be well! So the two files must be different. Git does not know which file to use: the one from the tip of auth_images , or the different one from the tip of master ? Or perhaps the right thing is to combine parts of each!

If you know for sure that exactly one of these two files is the right one, simply extract that one from that commit now:

git checkout master -- somenewfile

or:

git checkout auth_images -- somenewfile

Remember, these two are by definition different: if they were the same, Git would not have complained. So be sure that you get the right one.

The act of checking out the right one from the right branch tip will resolve this particular file. Repeat for every other add/add conflict for which some particular file from one of the two branch-tips is correct. Assuming these were the only problems, your git status will now say that all problems are resolved and the merge is ready to commit, and you can now run:

git commit

to complete the merge.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM