git
Block 2.2: History
git log
Background: https://giphy.com/gifs/back-to-the-future-dgEIhYAo3lZiE
We can see the history of our committed changes, called commits
using git log
.
git log
# commit ed226e022f60d9f578265c2c246367f5f07756de (HEAD -> main)
# Author: Jan Simson <git@simson.io>
# Date: Fri Sep 16 17:00:03 2022 +0200
# Edit hello.txt
# commit 795780d123f6eeedaa09734005c08d1ad89c1976
# Author: Jan Simson <git@simson.io>
# Date: Fri Sep 16 16:59:45 2022 +0200
# Adding hello.txt
# lines 1-9
You can move up and down with the arrow keys and leave the log view by pressing q
.
git log
of your respositorygit checkout
Background: https://giphy.com/gifs/back-to-the-future-xsF1FSDbjguis
git checkout
You can go back to any previous commit (and many other things!) with git checkout
.
git log
# commit ed226e022f60d9f578265c2c246367f5f07756de (HEAD -> main)
# Author: Jan Simson <git@simson.io>
# Date: Fri Sep 16 17:00:03 2022 +0200
# Edit hello.txt
# commit 795780d123f6eeedaa09734005c08d1ad89c1976
# Author: Jan Simson <git@simson.io>
# Date: Fri Sep 16 16:59:45 2022 +0200
# Adding hello.txt
# lines 1-9
git checkout
You can go back to any previous commit (and many other things!) with git checkout
.
git checkout
You can go back to any previous commit (and many other things!) with git checkout
.
Tip
You don’t need to pass the whole commit hash, just the first few characters are usually enough.
git checkout
You can go back to any previous commit (and many other things!) with git checkout
.
git checkout 795780d
# Note: switching to '795780d123f6eeedaa09734005c08d1ad89c1976'.
#
# 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 switching back to a branch.
#
# If you want to create a new branch to retain commits you create, you may
# do so (now or later) by using -c with the switch command. Example:
#
# git switch -c <new-branch-name>
#
# Or undo this operation with:
#
# git switch -
#
# Turn off this advice by setting config variable advice.detachedHead to false
#
# HEAD is now at 795780d Adding hello.txt
HEAD
, everything OK? 🤕detached HEAD
HEAD
is always the currently checked out state of your repository
HEAD
is detached, it is not associated with a branchHEAD
our changes will be lostmain
with git checkout main
HEAD
in e.g. the git log
or Sourcetree viewHEAD
can be used to reference commits relatively
HEAD
the current commitHEAD~1
the previous commitHEAD~2
two commits agogit log
of your respositoryHEAD~1
main
branchAny Questions?