I made some mistakes when merging commits of my colleagues. Now, we have discovered it and we need to apply old commit again, to choose manually the changes in the files. The situation looks like this:
A--\ /--F--\
C--D--E H--I
B--/^ \--G--/ ^
| |
WRONG MERGE MASTER
I need git to ask me again to merge B with I, like B had never been in the history. In other words, I need git to ask me to choose the merge for all the files which differs in B and I commits. What's the best approach to do such thing? Can I achieve this with cherry pick? How?
Changing the Last Commit: git commit --amend. The git commit --amend command is a convenient way to modify the most recent commit. It lets you combine staged changes with the previous commit instead of creating an entirely new commit.
As a general rule, when merging a pull request from a feature branch with a messy commit history, you should squash your commits. There are exceptions, but in most cases, squashing results in a cleaner Git history that's easier for the team to read.
You could use commit duplication trick:
# make a branch named B started on the commit B
git checkout -b B <sha1 id of the commit B>
# it creates a branch which starts at a commit
# right before B and has exact copy of commit as B,
# but with a different sha1 id.
git rebase --no-ff HEAD~1
# now we do simple merge
git checkout master
git merge B
It also allows to make the trick with range of commits and preserves dates, authors, commit messages and so on.
In fact your scenario is described in documentation:
--no-ff
... recreates the topic branch with fresh commits so it can be remerged successfully
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With