How to Backtrack in Git
Learn different ways to undo changes made to a Git project and when to use them.
StartKey Concepts
Review core concepts you need to learn to master this subject
Showing Latest Commit Log
Git Reset Using SHA
Staging Multiple Files
Remove File from Staging
Rolling Back to Last Commit
Showing Latest Commit Log
Showing Latest Commit Log
$ git show HEAD
commit 735359632f3ca3fe572484a4ec3e0d7b0d9c8f2d
Author: codecademy <[email protected]>
Date: Wed Jul 6 10:20:58 2016 -0400
scene-5.txt
diff --git a/scene-5.txt b/scene-5.txt
index b12dd97..5dd5d4e 100644
--- a/scene-5.txt
+++ b/scene-5.txt
@@ -12,3 +12,7 @@ Hamlet:
I will.
+Ghost:
+My hour is almost come,
+When I to sulphurous and tormenting flames
+Must render up myself.
\ No newline at end of file
In Git, the commit you are currently on is known as the HEAD
commit.
The output of the git show HEAD
command will display everything the git log
command displays for the HEAD
commit, plus all the file changes that were committed.
- 1When working on a Git project, sometimes we make changes that we want to get rid of. Git offers a few eraser-like features that allow us to undo mistakes during project creation. In this lesson, we…
- 2In Git, the commit you are currently on is known as the HEAD commit. In many cases, the most recently made commit is the HEAD commit. To see the HEAD commit, enter: git show HEAD The output o…
- 3What if you decide to change the ghost’s line in the working directory, but then decide you wanted to discard that change? You could rewrite the line how it was originally, but what if you forgot …
- 4The hamlet repository we are working on contains five files. In Git, it’s common to change many files, add those files to the staging area, and commit them to a repository in a single commit. …
- 5Great! The files you’ve added to the staging area belong in the same commit. What if, before you commit, you accidentally delete an important line from scene-2.txt? Unthinkingly, you add __sce…
- 6Creating a project is like hiking in a forest. Sometimes you take a wrong turn and find yourself lost. Just like retracing your steps on that hike, Git enables you to rewind to the part before you…
- 7To better understand git reset commit_SHA, notice the diagram on the right. Each circle represents a commit. Before reset: * HEAD is at the most recent commit After resetting: * HEAD g…
- 8Congratulations! You’ve learned three different ways to backtrack in Git. You can use these skills to undo changes made to your Git project. Let’s take a moment to review the new commands: * git…
What you'll create
Portfolio projects that showcase your new skills
Poem Fiasco
It's time to build fluency in Git fundamentals. In this next Pro Project, we're going to practice resetting HEAD in Git so you can hone your skills and feel confident taking them to the real world. Why? Whenever you have problems with your code and you want to start over, resetting to the HEAD is a great option. What's next? A poet, backtracking, more Git. You got this!
ASCII Portfolio
It's time to build fluency in Git fundamentals. In this next Pro Project, we're going to practice git commits in Git so you can hone your skills and feel confident taking them to the real world. Why? Making git commits is a safe way to save the current state of your work. What's next? Keyboard art, erasing, more Git. You got this!
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory