4 Tools for Working Locally

4.1 git stash

The git stash command stores away your current local changes to revert to the previous commit. This is typically done when you have made changes to a repository that you have not committed and want to undo.

4.1.1 Command Line

Suppose you already have local changes in the repository that you want to stash away. One case you may want to do this is if there are local, uncommitted changes in your repository, and you want to pull the latest changes using git pull. To stash changes in command line:

  1. Open Terminal, and navigate to desired directory:

    $ cd ~/cmu/76270/project4/github-instructions/
  2. Clear uncommitted changes:

    $ git stash

    Now observe that your local changes are now gone. To bring these changes back, you can run the following command:

    $ git stash pop

4.2 git log

The git log command allows you to see the history of commits made to your repository.

4.2.1 Command Line

To see the history of commits:

  1. Open Terminal, and navigate to desired directory:

    $ cd ~/cmu/76270/project4/github-instructions/
  2. To view commit history:

    $ git log

    Now observe the history of commits to this repository. What you will see in your terminal is a series of commits in the following format:

    Each commit has a commit hash, the user who made the commit, the time of the commit, and the commit message. The name of the branch, the commit hash, and the commit message are denoted in the above figure.

4.2.2 GitHub

We can also see a log of our commits in GitHub. This can be done as follows:

  1. From the homepage of your Git repository on GitHub, click on the “Commits” tab:

  1. Now we can see the history of commits, in the following format:

  1. To view a commit in more detail, click on the commit message. Now you will see how that commit modified the files in our repository. The lines highlighted in red denotes what was removed, and lines highlighted in green show what was added:

4.3 git diff

The git diff command allows you to see local changes you have made, but not yet committed, to your repository.

4.3.1 Command Line

To see your local changes:

  1. Open Terminal, and navigate to desired directory:

    $ cd ~/cmu/76270/project4/github-instructions/
  2. To view local changes:

    $ git diff

    Now observe your local changes to this repository. The file name is highlighted in the following figure. Meanwhile, lines with red text show the contents of the file that were deleted while lines with green text show the added content since your last commit.

    While you are in diff, you may hit the Enter or Return key to see more lines of differences. You may also hit Q to exit.