Git - Undoing Local Changes - before staging

From EdWiki

Revision as of 10:00, 23 June 2015 by Jshankar (Talk | contribs) (1 revision imported: EdWiki -- From Shukra)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

GitLab - Undoing Local Changes (before staging)

  • Goals
    Learn how to revert changes in the working directory
  • Checkout Master
    Make sure you are on the lastest commit in master before proceeding.
git checkout master
  • Change hello.c
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[]) {
    if( argc > 1 ) {
        puts("Hello ");
        puts(argv[1]);  /* This is a bad comment.  We want to revert it.*/
    } else {
        puts("Hello World!!!"); /* prints !!!Hello World!!! */
    return EXIT_SUCCESS;
  • Check the Status
git status

We see that the hello.c file has been modified, but hasn’t been staged yet.

  • Revert the changes in the working directory
    Use the checkout command to checkout the repository’s version of the hello.c file.
git checkout hello.c
git status
cat hello.c

The status command shows us that there are no outstanding changes in the working directory. And the “bad comment” is no longer part of the file contents.