John Blischak Add an extra `git status` call to explain the subtelties of `git diff` and `git checkout`.  over 8 years ago

Commit id: 15f65db21b32289c1e69a5ba4d3e477cce188ae9

deletions | additions      

       

union.cut(range(3)).saveas(data + "/sites-union.bed")  \end{verbatim}  You can view all Because Git is tracking \verb|clean.py|, it recognizes that  the unstaged differences between file has been changed since  thecurrent version and  last committed version of commit.  \begin{verbatim}  $ git status  # On branch master  # Changes not staged for commit:  # (use "git add ..." to update what will be committed)  # (use "git checkout -- ..." to discard changes in working directory)  #  # modified: clean.py  #  no changes added to commit (use "git add" and/or "git commit -a")  \end{verbatim}  The report from \verb|git status| indicates that  the file by running changes to \verb|clean.py| are not staged, i.e. they are in the working directory (Figure 1).  To view the unstaged changes, run  the command \verb|git diff|. \begin{verbatim}  $ git diff 

The new line starts with \verb|+| and the previous line starts with \verb|-|.  You can ignore the first five lines of output because they are directions for other software programs that can merge changes to files.  If you wanted to save keep  this edit, you could add \verb|clean.py| to the staging area using \verb|git add| and then commit the change using \verb|git commit|, as you did above. Instead, this time restore undo  the last committed version edit by following the directions from the output  of \verb|git status| to ``discard changes in  the file working directory''  using the command \verb|git checkout|. \begin{verbatim}  $ git checkout -- clean.py  $ git diff  \end{verbatim}  Now \verb|git diff| returns no output because \verb|git checkout| reverted \verb|clean.py| to the version in undid  the last commit. unstaged edit you had made to \verb|clean.py|.  And this ability to revert to undo  past versions of edits to  a file is not limited to just unstaged changes in  the last commit. working directory.  If you had committed multiple changes to the file \verb|clean.py| and then decided you wanted the original version, version from the initial commit,  you could replace the argument \verb|--| with the commit identifier of the first commit you made above  (we only need to specify the first seven characters for it to be unique). The \verb|--| used above was simply a placeholder for the first argument because by default \verb|git checkout| restores the most recent version of the file. file from the staging area (if you haven't staged any changes to this file, as is the case here, the version of the file in the staging area is identical to the version in the last commit).  \begin{verbatim}  $ git checkout 660213b clean.py  \end{verbatim}  At this point, you have learned the commands needed to version your code with Git.  Thus you already have the benefits of being able to make edits to files without copying them first, to create a record of your changes with accompanying messages, and to revert to previous versions of the files if needed.  Now you will always be able to recreate past results that were generated with previous versions of the code and see the exact changes you have made over the course of a project.