0% found this document useful (0 votes)
49 views2 pages

Git HEAD Commit Management Guide

This document provides a cheatsheet for using Git and GitHub, focusing on commands for backtracking, rolling back changes, staging multiple files, and removing files from the staging area. Key commands include 'git show HEAD' to view the latest commit, 'git checkout HEAD filename' to revert changes, and 'git reset HEAD filename' to unstage files. It also explains how to reset to a previous commit using its SHA value.

Uploaded by

isabella
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views2 pages

Git HEAD Commit Management Guide

This document provides a cheatsheet for using Git and GitHub, focusing on commands for backtracking, rolling back changes, staging multiple files, and removing files from the staging area. Key commands include 'git show HEAD' to view the latest commit, 'git checkout HEAD filename' to revert changes, and 'git reset HEAD filename' to unstage files. It also explains how to reset to a previous commit using its SHA value.

Uploaded by

isabella
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Cheatsheets / Git and Github, Part I

How to Backtrack in Git


Showing Latest Commit Log
In Git, the commit you are currently on is known as the
HEAD commit. $ git show HEAD
The output of the git show HEAD command will display commit
everything the git log command displays for the HEAD 735359632f3ca3fe572484a4ec3e0d7b0d9c8f2d
commit, plus all the file changes that were committed. Author: codecademy
<exampleuser@[Link]>
Date:   Wed Jul 6 [Link] 2016 -0400

    [Link]

diff --git a/[Link] b/[Link]


index b12dd97..5dd5d4e 100644
--- a/[Link]
+++ b/[Link]
@@ -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

Rolling Back to Last Commit


In Git, the git checkout HEAD filename command rolls back
all changes that have been made to filename since the $ git checkout HEAD [Link]
last commit. In other words, this command will change $ git diff
your working directory to look exactly as it did when you $
last made a commit.
You can use the git diff command to see if the rollback
was successful. If git diff doesn’t output anything, this
means your working directory matches your last commit.
Staging Multiple Files
In Git, the git add filename_1 filename_2 command is used
to add multiple files to the staging area at once. $ git add [Link] [Link]
You can use git status to check if you properly added $ git status
your files to the staging area. On branch master
Changes to be committed:
  (use ""git reset HEAD <file>..."" to
unstage)

        modified:   [Link]
        modified:   [Link]

Remove File from Staging


In Git, the git reset HEAD filename command will remove
filename from the staging area. Note that this command $ git reset HEAD [Link]
does not discard file changes from the working directory. Unstaged changes after reset:
You might use this command if you’ve added a file to the M       [Link]
staging area, but the file includes incorrect edits.
You can use the git status command to make sure your
file was properly removed from the staging area.

Git Reset Using SHA


In Git, the git reset commit_SHA command can be used to
set HEAD to the commit_SHA commit. The commit_SHA $ git log
argument is the first seven digits of a previous commit’s commit
SHA. In this example, the HEAD was reset to the commit 9d63f80111447544c303e9f1776fa08593a87310
made on Wed Jan 6 . Author: codecademy
You can use git log to see a record of previous commits
<exampleuser@[Link]>
and their SHA values.
Date:   Wed Jan 13 [Link] 2021 +0000

    Added updates to the file

commit
3ba6efbeece6ed530d85de5e313e52123fdf8cb4
Author: codecademy
<exampleuser@[Link]>
Date:   Wed Jan 6 [Link] 2021 -0400

    Completed first line of dialogue

$ git reset 3ba6efb

You might also like