2021-01-05 16:58:42 +01:00
|
|
|
title = Go back to where you were before
|
|
|
|
cards = checkout reflog
|
|
|
|
|
|
|
|
[description]
|
|
|
|
|
|
|
|
Say you were looking at something in the past, and then switched back to the main branch.
|
|
|
|
|
2024-08-22 10:28:06 +02:00
|
|
|
But then, you got reaaally distracted, and after your lunch break, you can't remember which past commit you were on before. How can you find out?
|
2021-01-05 16:58:42 +01:00
|
|
|
|
2024-08-22 10:28:06 +02:00
|
|
|
There's a convenient command that shows you all the places your HEAD has pointed to in the past:
|
2021-01-05 16:58:42 +01:00
|
|
|
|
|
|
|
git reflog
|
|
|
|
|
|
|
|
[setup]
|
|
|
|
|
|
|
|
for i in {1..10}; do
|
|
|
|
git commit --allow-empty -m $i
|
|
|
|
git branch $i
|
|
|
|
done
|
|
|
|
git checkout 3
|
|
|
|
git checkout main
|
|
|
|
|
|
|
|
[win]
|
|
|
|
|
|
|
|
# Find out where you've been before, and go back there!
|
|
|
|
test "$(git rev-parse HEAD)" = "$(git rev-parse 3)"
|