Commit 3856cd0a authored by Barron, Tom's avatar Barron, Tom Committed by GitLab
Browse files

My plan for recovering from 'detached HEAD' state

parent 2164f8e3
We've all done it. You deleted a file three commits ago and now you
need it back after all. So you go looking back through git log...
commit be1ddb4657efe46c2f60650026009288b9d94a8e
Merge: 604a052 9ab0b2b
Author: French, Robert D <frenchrd@ornl.gov>
Date: Tue Jan 3 10:35:26 2017 -0500
Merge branch 'gitting-unlost' into 'master'
Don't panic -- gitting unlost
(suggested by @tpb)
See merge request !4
commit 9ab0b2bbc81a7443bffba689596c1525b75e5fcd
Author: robertdfrench <frenchrd@ornl.gov>
Date: Tue Jan 3 10:34:50 2017 -0500
Don't panic -- gitting unlost (suggested by @tpb)
commit 604a05277816a8b6c599c2420e8cecf3302a5854
Author: French, Robert D <frenchrd@ornl.gov>
Date: Thu Dec 29 09:56:50 2016 -0500
Reminder to submit workshops to ORNL Today
commit 957bc7f8d4c96fe4a267282a59bf694545a7c897
Author: French, Robert D <frenchrd@ornl.gov>
Date: Thu Dec 29 09:32:49 2016 -0500
Move 12/29 to Recent Workshops
commit 40c78ed75bd3c5ce16f8f16d5186450d20b26c96
Author: French, Robert D <frenchrd@ornl.gov>
Date: Thu Dec 29 09:30:27 2016 -0500
Reminder to set up BlueJeans for each meeting
commit eca3bedcf0239321cb59bc6e4480642ac11a2e9f
Author: French, Robert D <frenchrd@ornl.gov>
Date: Wed Dec 28 15:01:59 2016 -0500
Add BlueJeans Link
...
Oh, yeah! It's in 40c78ed75bd3c5ce16f8f16d5186450d20b26c96
$ git checkout 40c78ed75bd3c5ce16f8f16d5186450d20b26c96
Note: checking out '40c78ed75bd3c5ce16f8f16d5186450d20b26c96'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
HEAD is now at 40c78ed... Reminder to set up BlueJeans for each meeting
Umm... Okay. So I've copied the file I want someplace safe. Now how do
I get back to where I was? Maybe 'git log' will let me get back to my
current tip?
But no, the output of 'git log' now starts with the commit I just
checked out. How do I find my subsequent commits? Are they still
there? Oh no!
$ git log
commit 40c78ed75bd3c5ce16f8f16d5186450d20b26c96
Author: French, Robert D <frenchrd@ornl.gov>
Date: Thu Dec 29 09:30:27 2016 -0500
Reminder to set up BlueJeans for each meeting
commit eca3bedcf0239321cb59bc6e4480642ac11a2e9f
Author: French, Robert D <frenchrd@ornl.gov>
Date: Wed Dec 28 15:01:59 2016 -0500
Add BlueJeans Link
commit a7eb7fea1921aae01bacefb03d0a5eaedfb853fa
Author: French, Robert D <frenchrd@ornl.gov>
Date: Wed Dec 28 15:01:27 2016 -0500
Add BlueJeans Link
commit 526b5fd30e08a630b9ce8a14594e050dda4757b5
Author: French, Robert D <frenchrd@ornl.gov>
Date: Wed Dec 28 14:59:44 2016 -0500
Move cancelled 12/22 topic to 2/16
commit 27fac7af17eea381b3c03c2c894de50724768468
Merge: 7b49484 5c2f9e9
Author: French, Robert D <frenchrd@ornl.gov>
Date: Wed Dec 28 14:53:45 2016 -0500
Merge branch 'branches-for-fun-and-profit' into 'master'
Add slides for Branches talk
See merge request !3
Don't panic. 'git branch -a' will clarify things:
$ git branch -a
* (HEAD detached at 40c78ed)
master
remotes/origin/HEAD -> origin/master
remotes/origin/master
remotes/origin/tpb-rf9-dont-panic-gitting-unlost
I can get back to my master branch simply checking out master
$ git checkout master
Previous HEAD position was 40c78ed... Reminder to set up BlueJeans for each meeting
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.
And now 'git log' shows everything again
commit be1ddb4657efe46c2f60650026009288b9d94a8e
Merge: 604a052 9ab0b2b
Author: French, Robert D <frenchrd@ornl.gov>
Date: Tue Jan 3 10:35:26 2017 -0500
Merge branch 'gitting-unlost' into 'master'
Don't panic -- gitting unlost
(suggested by @tpb)
See merge request !4
commit 9ab0b2bbc81a7443bffba689596c1525b75e5fcd
Author: robertdfrench <frenchrd@ornl.gov>
Date: Tue Jan 3 10:34:50 2017 -0500
Don't panic -- gitting unlost (suggested by @tpb)
commit 604a05277816a8b6c599c2420e8cecf3302a5854
Author: French, Robert D <frenchrd@ornl.gov>
Date: Thu Dec 29 09:56:50 2016 -0500
Reminder to submit workshops to ORNL Today
commit 957bc7f8d4c96fe4a267282a59bf694545a7c897
Author: French, Robert D <frenchrd@ornl.gov>
Date: Thu Dec 29 09:32:49 2016 -0500
Move 12/29 to Recent Workshops
commit 40c78ed75bd3c5ce16f8f16d5186450d20b26c96
Author: French, Robert D <frenchrd@ornl.gov>
Date: Thu Dec 29 09:30:27 2016 -0500
Reminder to set up BlueJeans for each meeting
commit eca3bedcf0239321cb59bc6e4480642ac11a2e9f
Author: French, Robert D <frenchrd@ornl.gov>
Date: Wed Dec 28 15:01:59 2016 -0500
Add BlueJeans Link
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment