Reputation: 2114
I have a branch A and master in a git repo.
In branch A I have done several additions, deletions. At some point, these changes were also merged in Master but we had to release master without these changes so we removed the file in master.
Now, when merging master into branch A, to get the last changes, Git obviously deletes the files since they have been deleted in master after the last changes.
What is the easiest way to keep branch A changes while merging back last Master changes?
Upvotes: 3
Views: 795
Reputation: 19025
I would go ahead and merge master into A, and then cherry-pick the commits that were undone back onto A. So let's say you the files you had added were done in commit abc123; while on A, simply do git cherry-pick abc123
. Repeat for all commits whose changes were undone, or if they are a contiguous list of commits, you can specify a range to cherry-pick, e.g. git cherry-pick 123..xyz
.
Upvotes: 0
Reputation: 41945
What git
does makes sense, it sounds like you agree with that. I'd let git
do what it does and keep the default merge commit, then re-add the missing file in an extra commit:
$ git checkout master
$ git merge A # the file is gone
$ git checkout A -- file.txt
$ git add file.txt
$ git commit -m"Reintroduce file.txt, which was deleted for release"
I don't like modifying merge commits manually, rather let git
do them, then fix afterwards. It causes less surprise.
Upvotes: 2