I have two remotes in git, namely 'origin' and 'upstream'. origin was forked off upstream at some point, and both have had several commits since the fork. Now I want to bring over many (but not all) of the commits that have occurred on 'upstream' to 'origin'. So my sequence of operation is as follows:-
1- Fetch all the changes from the remote repositories and update local master (I'm on the master branch):-
git fetch origin
git fetch upstream
git rebase origin/master
2- List the difference in commits between local master and upstream's master:-
git cherry -v master upstream/master
After seeing that I see that there are many commits with the (+) sign:-
+ abcdabcdabcdabcdabcdabcdabcdabcdabcd First different commit
+ 123412341234123412341234123412341234 Second different commit
+ efabefabefabefabefabefabefabefabefab Third different commit
+ 567856785678567856785678567856785678 Fourth different commit
+ a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1 Fifth different commit
3- I'm interested in cherry-picking the fourth commit, so I proceed with the following command (ensuring that I am on branch master first):-
git cherry-pick 567856785678567856785678567856785678
4- At this point, I perform git cherry again as listed in step 2:-
git cherry -v master upstream/master
I expected the output would be different because the Fourth commit would have (-). However, the output after this command is still the same:-
+ abcdabcdabcdabcdabcdabcdabcdabcdabcd First different commit
+ 123412341234123412341234123412341234 Second different commit
+ efabefabefabefabefabefabefabefabefab Third different commit
+ 567856785678567856785678567856785678 Fourth different commit
+ a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1a1 Fifth different commit
I have double checked my log in master and I can see that the Fourth commit has been added. Is there something else I need to do in order to see the change in the git cherry output? What do I need to do in order to properly get the difference between origin/master and upstream/master?
I am using git on Windows version 2.11.0.windows.1.
It happens when cherry-picked commit has conflicts with your branch, so you need to resolve them by adjusting code changes. As a result, git cherry
can't figure out, that new commit is identical to its originator, so it shows original commit in the list of changes to be applied. This post touches described situation. Note, that post isn't fully accurate as described in comments below it.