Reputation: 2590
Let's say I made a, b, c, d
commits so far. I'm currently in d
and I want to go back to a
.
a
and d
are in master
branch. b
and c
are temp
branch.
In this case, if I run git reset --hard <a's commit>
, will I lose the commit b
and c
because they are made after a
? Is it true even though they are in another branch?
Upvotes: 4
Views: 5170
Reputation: 25423
The commit history of the other branch (temp
) will not be altered if you run your reset
command while on the master
branch.
The reset
command actually will never delete a commit or change the content of a branch that you do not have currently checked out. It is just simply moving your HEAD
pointer around.
A very useful tool that is worth mentioning is the reflog. Every time you create a commit (or the tip of a branch is updated) an entry is stored in the reflog. You can see the contents of the reflog with: git reflog
.
So, if you ever feel that you've "lost" a commit, you can search for it in the reflog and cherry-pick it back.
Upvotes: 6