Tracking Changes
We will use this repository to track a simple version of our transcriptome analysis pipeline.
Create a new file called transcriptome.txt
in your repo:
$ pwd
/home1/03439/wallen/my_first_repo
$ touch transcriptome.txt
$ ls
transcriptome.txt
Open the file with VIM and enter the following text:
$ vim transcriptome.txt
Now in VIM:
(press 'i' to enter insert mode)
Step 1: Map reads with tophat
(press Esc then :wq to save and quit)
$ cat transcriptome.txt
Step 1: Map reads with tophat
Start Tracking a New File
If we check the status of our project again, Git tells us that it’s noticed the new file:
$ git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
transcriptome.txt
nothing added to commit but untracked files present (use "git add" to track)
The “untracked files” message means that there’s a file in the directory
that Git isn’t keeping track of.
We can tell Git to track a file using git add
:
$ git add transcriptome.txt
And then check for the expected behavior:
$ git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: transcriptome.txt
Commit Changes to the Repo
Git now knows that it’s supposed to keep track of transcriptome.txt
,
but it hasn’t recorded these changes as a commit yet.
To get it to do that,
we need to run one more command:
$ git commit -m "Started notes on transcriptome analysis"
[master (root-commit) 39e316e] Started notes on transcriptome analysis
1 file changed, 1 insertion(+)
create mode 100644 transcriptome.txt
When we run git commit
,
Git takes everything we have told it to save by using git add
and stores a copy permanently inside the special .git
directory.
This permanent copy is called a “commit”
(or “revision”) and its short identifier is 39e316e
.
Your commit may have another identifier.
We use the -m
flag (for “message”)
to record a short, descriptive, and specific comment that will help us remember later on what we did and why.
Good commit messages start with a brief (<50 characters) statement about the
changes made in the commit. Generally, the message should complete the sentence “If applied, this commit will”
If we run git status
now:
$ git status
On branch master
nothing to commit, working directory clean
it tells us everything is up to date.
Check the Project History
If we want to know what we’ve done recently,
we can ask Git to show us the project’s history using git log
:
$ git log
commit 39e316e4afe33957495a328750c72834551bd9f1
Author: Joe Allen <wallen@tacc.utexas.edu>
Date: Fri Jul 13 10:49:08 2018 -0500
Started notes on transcriptome analysis
git log
lists all commits made to a repository in reverse chronological order.
The listing for each commit includes
the commit’s full identifier
(which starts with the same characters as
the short identifier printed by the git commit
command earlier),
the commit’s author,
when it was created,
and the log message Git was given when the commit was created.
Exercise
- Take a moment to browse the
.git/
directory to see if you can find where the changes are stored
Making Further Changes
Now suppose we add more information to the file. Edit the file with VIM
to add Step 2 of transcriptome analysis:
$ vim transcriptome.txt
Now in VIM:
(press 'i' to enter insert mode)
Step 2: Assemble transcripts with cufflinks
(press Esc then :wq to save and quit)
$ cat transcriptome.txt
Step 1: Map reads with tophat
Step 2: Assemble transcripts with cufflinks
When we run git status
now,
it tells us that a file it already knows about has been modified:
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: transcriptome.txt
no changes added to commit (use "git add" and/or "git commit -a")
The last line is the key phrase:
“no changes added to commit”.
We have changed this file,
but we haven’t told Git we will want to save those changes
(which we do with git add
)
nor have we saved them (which we do with git commit
).
So let’s do that now. It is good practice to always review
our changes before saving them. We do this using git diff
.
This shows us the differences between the current state
of the file and the most recently saved version:
$ git diff
diff --git a/transcriptome.txt b/transcriptome.txt
index 0495f06..dc3ae88 100644
--- a/transcriptome.txt
+++ b/transcriptome.txt
@@ -1 +1,2 @@
Step 1: Map reads with tophat
+Step 2: Assemble transcripts with cufflinks
The output is cryptic because
it is actually a series of commands for tools like editors and patch
telling them how to reconstruct one file given the other.
If we break it down into pieces:
- The first line tells us that Git is producing output similar to the Unix
diff
command comparing the old and new versions of the file. - The second line tells exactly which versions of the file
Git is comparing;
0495f06
anddc3ae88
are unique computer-generated labels for those versions. - The third and fourth lines once again show the name of the file being changed.
- The remaining lines are the most interesting, they show us the actual differences
and the lines on which they occur.
In particular,
the
+
marker in the first column shows where we added a line.
After reviewing our change, it’s time to commit it:
$ git add transcriptome.txt
$ git commit -m "Added step 2 to transcriptome analysis"
[master cfe5306] Added step 2 to transcriptome analysis
1 file changed, 1 insertion(+)
$ git status
On branch master
nothing to commit, working directory clean
Git insists that we add files to the set we want to commit before actually committing anything. This allows us to commit our changes in stages and capture changes in logical portions rather than only large batches. For example, suppose we’re adding a few citations to relevant research to our thesis. We might want to commit those additions, and the corresponding bibliography entries, but not commit some of our work drafting the conclusion (which we haven’t finished yet).
To allow for this, Git has a special staging area where it keeps track of things that have been added to the current changeset but not yet committed.
Staging Area
If you think of Git as taking snapshots of changes over the life of a project,
git add
specifies what will go in a snapshot
(putting things in the staging area),
and git commit
then actually takes the snapshot, and
makes a permanent record of it (as a commit).
Let’s watch as our changes to a file move from our editor to the staging area and into long-term storage. First, we’ll add another line to the file:
$ vim transcriptome.txt
Now in VIM:
(press 'i' to enter insert mode)
Step 3-4: Final transcriptome assembly with cuffmerge
(press Esc then :wq to save and quit)
$ cat transcriptome.txt
Step 1: Map reads with tophat
Step 2: Assemble transcripts with cufflinks
Step 3-4: Final transcriptome assembly with cuffmerge
Now check the changes:
$ git diff
diff --git a/transcriptome.txt b/transcriptome.txt
index fe7c565..61f7805 100644
--- a/transcriptome.txt
+++ b/transcriptome.txt
@@ -1,2 +1,3 @@
Step 1: Map reads with tophat
Step 2: Assemble transcripts with cufflinks
+Step 3-4: Final transcriptome assembly with cuffmerge
So far, so good:
we’ve added one line to the end of the file
(shown with a +
in the first column).
Now let’s put that change in the staging area
and see what git diff
reports:
$ git add transcriptome.txt
$ git diff
There is no output: as far as Git can tell, there’s no difference between what it’s been asked to save permanently and what’s currently in the directory. However, if we do this:
$ git diff --staged
diff --git a/transcriptome.txt b/transcriptome.txt
index fe7c565..61f7805 100644
--- a/transcriptome.txt
+++ b/transcriptome.txt
@@ -1,2 +1,3 @@
Step 1: Map reads with tophat
Step 2: Assemble transcripts with cufflinks
+Step 3-4: Final transcriptome assembly with cuffmerge
It shows us the difference between the last committed change and what’s in the staging area. Let’s save our changes:
$ git commit -m "Added steps 3-4 to transcriptome analysis"
[master 53baf60] Added steps 3-4 to transcriptome analysis
1 file changed, 1 insertion(+)
Check our status:
$ git status
On branch master
nothing to commit, working directory clean
And look at the history of what we’ve done so far:
$ git log
commit 53baf60a5ddeb490f8ed0542458abb7e850048e9
Author: William Allen <wallen@tacc.utexas.edu>
Date: Fri Jul 13 11:15:04 2018 -0500
Added steps 3-4 to transcriptome analysis
commit cfe53067828d2e7232503e4dfec43d9ac20e6cfb
Author: William Allen <wallen@tacc.utexas.edu>
Date: Fri Jul 13 10:59:46 2018 -0500
Added step 2 to transcriptome analysis
commit 39e316e4afe33957495a328750c72834551bd9f1
Author: William Allen <wallen@tacc.utexas.edu>
Date: Fri Jul 13 10:49:08 2018 -0500
Started notes on transcriptome analysis
Note on Directories
There are a couple important facts you should know about directories in Git. First, Git does not track directories on their own, only files within them. Try it for yourself:
$ mkdir directory
$ git status
$ git add directory
$ git status
Note, our newly created empty directory directory
does not appear in
the list of untracked files even if we explicitly add it (via git add
) to our
repository.
Second, if you create a directory in your Git repository and populate it with files, you can add all files in the directory at once by:
$ git add <directory-with-files>
Exercise
Here are the last two steps of transcriptome analysis:
Step 5: Compute differential expression with cuffdiff
Step 6-18: Plot expression data with cummerbund
- Add the rest of the steps of transcriptome analysis to your text file
- Add the modified file to the staging area
- Commit the modifications
- Browse the
.git/
folder to find where commits are located
Previous: Create a New Repository | Next: Exploring History | Top: Course Overview |