John Blischak Add text to clean.py so that git diff is more interpretable.  about 9 years ago

Commit id: 8f88061e257db87790d807d968ea22e7b27de067

deletions | additions      

       

# Setup  mkdir thesis  cd thesis  touch process.shclean.py  analyze.R echo '#!/usr/bin/env python  # Thesis project:  # Remove bad samples.  # Export clean data as a matrix.  # Usage: clean.py input [input ...] > data_clean.py  import sys  import os  ' > clean.py  # Version your code  git init  git config user.name "First Last" 

git add clean.py analyze.R  git commit -m "Add initial version of thesis code."  git log  echo "# Removes # Change description in clean.py  # +# Remove  samples with more than 5% missing data" > data.  # -# Remove bad samples.  nano  clean.py git diff  git checkout -- clean.py  git diff  git checkout 660213b91af167d992885e45ab19f585f02d4661 660213b  clean.py        

The commit identifier can be used to compare two different versions of a file, restore a file to a previous version from a past commit, and even retrieve tracked files if you accidentally delete them.  Now we are free to make changes to the files knowing that we can always revert them to the state of this commit by referencing its identifier.  As an example, we'll add edit \verb|clean.py|.  Here is the current top of  the comment "\# Removes file.  \begin{lstlisting}  $ head clean.py  #!/usr/bin/env python  # Thesis project:  # Remove bad samples.  # Export clean data as a matrix.  # Usage: clean.py input [input ...] > data_clean.py  import sys  import os  \end{lstlisting}  We'll update the description to explicitly define which samples are removed.  \begin{lstlisting}  $ head clean.py  #!/usr/bin/env python  # Thesis project:  # Remove  samples with more than 5\% 5%  missing data" to \verb|clean.py|. data.  # Export clean data as a matrix.  # Usage: clean.py input [input ...] > data_clean.py  import sys  import os  \end{lstlisting}  We can view all the differences between the current version and last committed version of the file by running the command \verb|git diff|.  \begin{lstlisting}  $ git diff  diff --git a/clean.py b/clean.py  index e69de29..5a3e47a c1fcad7..c0bfe5c  100644 --- a/clean.py  +++ b/clean.py  @@ -0,0 +1 -1,7 +1,7  @@ #!/usr/bin/env python    # Thesis project:  -# Remove bad samples.  +# Removes Remove  samples with more than 5% missing data.  # Export clean  data as a matrix.    # Usage: clean.py input [input ...] > data_clean.py  \end{lstlisting}  This shows us The new line starts with \verb|+| and  the one previous  line that we added to \verb|clean.py|. starts with \verb|-|.  We can ignore the first five lines of output because they are directions for other software programs that can merge changes to files.  If we wanted to save this edit, we could add \verb|clean.py| to the staging area using \verb|git add| and then commit the change using \verb|git commit|, as we did above.  Instead, this time we will restore the last committed version of the file using the command \verb|git checkout|.