I was working on a branch, and realized that I wanted changes from a different branch to help with my testing, but I didn't want to actually commit them to my current branch. So I used git merge --no-commit
to bring those changes into my current branch. Then I unstaged the changed files with git reset
and proceeded with my work and testing. Eventually I committed some changes related to my current work (but not the changes related to the other branch that I had brought in and unstaged).
I was confused to find that the commit history for my current branch now shows a commit from the "other branch" even though I never committed those changes here. I don't seem to actually have the changes, but looking through the log is confusing because it appears the changes were applied (and never removed) but they aren't here. So I think I got what I want in the end, but with a confusing history.
I realize now that what I did was presumably not a good way to accomplish my goals, but can anyone help me understand how the history works? I suppose there's some chance that I am misremembering exactly what I did too...
EDIT: Here's the most recent part of my git log graph. The part I don't understand now is why the actual changes from commit 34eaa54 do not appear at the head of my journal branch.
* 1c2e2d4 (HEAD -> journal, origin/journal) fix: make command consistent
* 4bedc14 fix: remove space
* 03499a4 fix: use subprocess instead
|\
| * 34eaa54 (origin/update, update) feat: use mock images
* | a8be334 feat: save journal
|/
* 8560394 (tag: v0.2.14, origin/master, origin/HEAD, master) Merge branch 'fix-timeout' into 'master'
EDIT2: Add reproducible example. If you follow these instructions then you can see at the end that you will have the half-aborted commit "in" branch-one
but the change isn't there (the word rabbit). The included git status
command explicitly mentions still being in the merge, despite the fact that I reset the changed file, so, as expected, that seems to be "why" this happens.
printf "the\nquick\nbrown\nfox\n" > a
git init
git add a
git commit -m "initial commit"
git checkout -b branch-one
sed -i 's/quick/fast/g' a
git add a
git commit -m "fix: fast"
git checkout master
git checkout -b branch-two
sed -i 's/fox/rabbit/g' a
git add a
git commit -m "fix: rabbit"
git checkout branch-one
git merge --no-commit branch-two
git reset -- a
touch b
git add b
git status
git commit -m "feat: add b"
git reset --hard
git log --graph --oneline
cat a