Is it possible to merge from one branch to another in git with only certain files?
Let’s say I have two branches
I want to merge the changes in
A has some files that I changed as well as some files that someone else changed. For example, in
A, there are 2 files that changed.
- Xcode 6.0.1 crashes when merging 2 branches
- Undo a merge after time, what happens?
- git errors sharing files among Windows and Mac
- stop git merge from opening text editor
- How do I resolve conflicts with Git?
- Git: is there a quicker way to merge from one branch to multiple branches than doing each one serially?
- path/to/JavaFile1.java (I changed this file)
- path/to/another/JavaFile2.java (another user changed this file)
On merging from
B, I find that there are conflicts with the file that someone else changed (in the running example,
JavaFile2.java). Now, I want the merge to proceed so as to
- “ignore” or “skip” the file that was changed by someone else (I don’t know how to resolve that conflict)
- I want the merge to be such that when someone else merges, they too will also have to deal with the conflict and decide what to do.
I am not sure if a resolution of using
theirs is appropriate, because on the next merge, it might never consider the conflict again (git will mark the conflicts as resolved in future merges).
I suppose I can cherry-pick too, but on our team, we have a policy to
merge forward (e.g. from
B) and cherry-pick backwards (e.g. from
Is it possible to do as I stated? We also have a policy that a developer must merge their own commits, but, unfortunately, this developer is not available for the next two weeks (vacation).
One Solution collect form web for “Is it possible to merge from one branch to another in git with only certain files?”
For me the conceptually easiest way to deal with this would be to perform the merge and then reset the file in question to the commit in
B which was at the
HEAD of that branch before the merge.
The command you would use to reset the file modified by another user is:
git checkout <SHA-1> path/to/another/JavaFile2.java
<SHA-1> is the hash of the most recent commit on
B before you did the merge (i.e. the version you want to keep).
If there is a merge conflict in this file during the merge, then you can reset it using the above command and commit. If the merge completes without a conflict, then you can still run the above command, and you can amend the merge commit:
git add path/to/another/JavaFile2.java git commit --amend