So I was on a detached head and I commited some changes. I am now on a different head, how do I return to my detached head change that thread to the master?
Thanks
$ git commit -m "Connect Users to Fitbit accounts"
[detached HEAD b3b8249] Connect Users to Fitbit accounts
17 files changed, 159 insertions(+), 3 deletions(-)
You can git checkout
the commit:
git checkout b3b8249
Branches are basically a named commit and git checkout
works with everything that can be resolved to a commit (Commits, Branches, Tags, the reflog), not only with branches.
As I mentioned the reflog: In case you don't remember the exakt commit hash the reflog is the way to go:
[root@/tmp/test (5d0f65b...)]git checkout master
Switched to branch 'master'
[root@/tmp/test master]touch b
[root@/tmp/test master]git add b
[root@/tmp/test master]git commit -m "Add b"
[master 9bf5987] Add b
0 files changed
create mode 100644 b
[root@/tmp/test master]git reflog
9bf5987 HEAD@{0}: commit: Add b
5d0f65b HEAD@{1}: checkout: moving from 5d0f65ba749c8f39773c4edb16ab40c5c58501d4 to master
The first column will tell you where the HEAD pointed at and you can retrieve the older state by passing HEAD@{N}
to git checkout
:
[root@/tmp/test master]git checkout HEAD@{1}
Note: checking out 'HEAD@{1}'.
...
HEAD is now at 5d0f65b... Add a
The reflog will save your head in certain situations as it allows you to retrieve almost anything that was lost, e.g. commits lost in a rebase, commits lost in a reset etc.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments