I have the following situation in my commit history:
A1-...-A2
\
B1-B2-...-B3----------B4-B5
\ /
C1-C2-C3
I then did (after git checkout A2
and a clean git status
)
git cherry-pick --no-commit C2..B5
.
Now, C2
introduced an important line in file1.txt
, say
file1.txt
-line x
+line x with new part
and "line x with new part" exists in all commits C2 to B5.
But after the cherry-pick, the change does not appear and file1.txt
still looks like
...
line x
...
where I expected a line "line x with new part". I thought, I don't understand the changes and did
git diff HEAD C2 file1.txt
file1.txt
-line x
+line x with new part
which shows the change as expected. I also checked
git diff HEAD C3 file1.txt
, git diff HEAD B4 file1.txt
and git diff HEAD B5 file1.txt
with the same result.
git rev-parse HEAD
results in A2
as intended and git status
says "On branch A, Your branch is up to date with 'origin/A'.
nothing to commit, working tree clean".
What do I miss? Any ideas?
References:
How to cherry pick a range of commits and merge into another branch,
How to merge a specific commit in Git and
Pull all commits from a branch, push specified commits to another (I hope,
it is not an issue with a comment from the answer "...Likewise, cherry picking a commit from one branch to another basically involves generating a patch,
then applying it, thus losing history that way as well." from the answer.).
Edit @eftshift0: After git cherry-pick --no-commit C1..B5
it looks correct at a first glance:
The Diff shows
<<<<<<< HEAD
line x # current status of A2
||||||| parent of C2...
line x # common ancestors of C1 and A2
=======
line x with new part # from merge (new stuff)
>>>>>>> C2...
From the docs:
git-cherry-pick - Apply the changes introduced by some existing commits SYNOPSIS
DESCRIPTION Given one or more existing commits, apply the change each one introduces, recording a new commit for each. This requires your working tree to be clean (no modifications from the HEAD commit).