Reputation: 3
This is what my git log looks like right now:
git log --topo-order --reverse --pretty=oneline
50d035a5a12db8a0b23f4910a0e387f1ad38524c 0
49c9fef259eb54182da6d70fa0425474accb29e0 3
a1108badac40942296d9c9d734a561a645144914 7
1d7e5ea36224169db465d2e413c36895b02cafea 11
c327029ebf8c442c45aaef090236650b50fb5e47 1
c64fcac8dd676084caacea4e20a0409926be7054 5
1e1f9e389341e4161f2aa8d6f868346d76b21e33 9
e98be40ea2066b65a980de20200f036d2f37b027 2
e5f8dfe7c8bd9d7e02eae85a5c534e2d2db23f4a 6
1439d018ed902b9fde247b8568dc0df1539700e5 10
663f06f969597ddf1a6eeb9ec7921775c7f1bc02 Merge branch 'b'
a9b044cf716d6de969ed0649017bf61cae3e9421 4
b8a76a56c5f29c63b82dd823ec0b5b45abcd655c 8
6c266c5bb7106821b63d7e2ddf09347022f570ac 12
9162a13adb1642f8434d0211cf15bf4ac06b9a4b Merge branch 'd'
a704f3284be8289a50468215a12f5a214ae6ab4f (HEAD -> master,
origin/master, origin/HEAD) Merge branch 'master' into c
I want to reset this to "1e1f9e389341e4161f2aa8d6f868346d76b21e33" sha1 (7th commit from the top). But when I do that, I lose several other commits that occurred before it. I realize that the reset is supposed to remove all changes that happened after the given commit, but in this case, it's removing those that occurred before too.
git reset --keep 1e1f9e389341e4161f2aa8d6f868346d76b21e33
git log --topo-order --reverse --pretty=oneline
50d035a5a12db8a0b23f4910a0e387f1ad38524c 0
c327029ebf8c442c45aaef090236650b50fb5e47 1
c64fcac8dd676084caacea4e20a0409926be7054 5
1e1f9e389341e4161f2aa8d6f868346d76b21e33 (HEAD -> master) 9
Where did the commits with messages "3", "7" and "11" go? How can I not lose those commits?
Upvotes: 0
Views: 40
Reputation: 1425
Since you are jumping to a point prior to those commits being merged
into master, they are not being displayed in your log
. If you just want to keep an easy reference to commits 3
, 7
, and 11
in your repository, then you can create a tag
or branch
at the top-most commit (in this case 11
).
You would then need to merge
it back into master; or rebase
it on top of master (but that will re-write the commits).
git tag <tag name> 1d7e5ea36224169db465d2e413c36895b02cafea
or
git branch <branch name> 1d7e5ea36224169db465d2e413c36895b02cafea
You will need to pass --all
to your log
command to see all the branches.
Instead of creating a branch
or tag
you could just merge
commit 11
into master.
git merge 1d7e5ea36224169db465d2e413c36895b02cafea
Upvotes: 1