Deletions are marked like this. | Additions are marked like this. |
Line 181: | Line 181: |
## | ## git |
This page is provided for FreeSurfer developers to assist in the CVS -> git transition.
This page is not meant to be a comprehensive guide for using git. Git is a feature loaded version control system which at times can be a bit of a hurdle to learn. However, when used in its simplest form, it can be very similar to most all other version control systems, including CVS. Below are many of the basic CVS commands used by FreeSurfer developers the git equivalent of that command.
The following sites are great resources for those who want to dig deeper and and learn more about git and its features.
Initial Git Setup
Very first thing to do. Add the following line to your .cshrc or .bashrc file.
## bash export PATH=/usr/pubsw/packages/git-annex/current/bin:$PATH ## csh setenv PATH "/usr/pubsw/packages/git-annex/current/bin":"$PATH"
When we start out using git we want to set a few of our configuration settings. We only need to do this one time:
$> cd ~ $> git config --global user.name "Zeke Kaufman" $> git config --global user.email zkaufman@nmr.mgh.harvard.edu $> git config --global color.ui true
For additional git specifics setting:
Checkout out the main branch
When working with CVS, we would checkout out the FreeSurfer repository using the cvs checkout dev command. In git we 'clone' repositories. This gives us a local version of the repository which we can work with:
## CVS $> cvs checkout dev ## git $> git clone /space/freesurfer/repo/freesurfer
Or check out a specific branch:
## CVS $> cvs checkout -r stable6 dev ## git $> git clone -b stable6 /space/freesurfer/repo/freesurfer
Additional information and examples:
Cloning-an-Existing-Repository
Cloning-an-Existing-Repository
Daily Workflow
Updating your code
In CVS, when we want the most up-to-date version of the code, we issue a cvs update command. This will update our files to the latest version, restore any missing files, and warn us of any conflicts. The nearest equivalent in git is the git pull command. This will update our local repository and update all the necessary files to the most recent version. It is good practice to always issue a git pull command before starting to work on any files.
## CVS $> cvs update ## git $> git pull
One major difference between cvs update and git pull command is that git pull will not restore any missing files (i.e. files that we deleted locally). In git, if we want to restore locally deleted files, we need to take the additional step of issuing a git checkout command. For example:
## CVS $> cvs update cvs update: warning: README was lost U README ## git $> git pull $> git status deleted: README.txt
Use the checkout command to restore a deleted file:
$> git checkout README.txt
Additional information and examples:
Modified files
Generating diffs between your working copy of the code, and the repository version, is also very similar with git and cvs. For example, say we want to know what files differ:
## CVS $> cvs update M README ## git $> git status modified: README.txt
To view the difference, use the diff command just as you would in CVS:
## CVS $> cvs diff README Index: README =================================================================== RCS file: /space/repo/1/dev/dev/README,v retrieving revision 1.13 diff -r1.13 README 20a21 > An example line of added text.
In git this looks like:
## git $> git diff README diff --git a/README b/README index 95ec88a..d4686af 100644 --- a/README +++ b/README @@ -18,3 +18,4 @@ +An example line of added text.
View log information
Again, CVS and git are very similar in this regard:
## CVS $> cvs log README ---------------------------- revision 1.13 date: 2016/04/08 20:27:48; author: nicks; state: Exp; lines: +1 -1 this change requires retesting EVERYTHING ---------------------------- ## git $> git log README commit 7fd91e12ec4e619c18cd11b0a156327322ffbfaf Author: Z K <zkaufman@nmr.mgh.harvard.edu> Date: Tue Apr 12 05:51:13 2016 -0400 this change requires retesting EVERYTHING
If we wanted to inspect the difference:
## CVS $> cvs diff -r 1.12 =================================================================== RCS file: /space/repo/1/dev/dev/README,v retrieving revision 1.12 diff -r1.12 README 1c1 < FreeSurfer © 2011 The General Hospital Corporation (Boston, MA) "MGH" --- > FreeSurfer © 2011-2016 The General Hospital Corporation (Boston, MA) "MGH" ## git $> git diff dd623df16051522125419 README diff --git a/README b/README index a4daeb1..95ec88a 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -FreeSurfer © 2011 The General Hospital Corporation (Boston, MA) "MGH" +FreeSurfer © 2011-2016 The General Hospital Corporation (Boston, MA) "MGH"
Commit a change
Git and CVS can be virtually identical when it comes to committing changes. The primary difference is that git requires the additional step of pushing to the central repository. This means issuing the git push command after committing all your changes:
## CVS $> git commit -m "Fixed a bug." <file_name> $> git commit -m "More debug information" <file_name> ## git $> git commit -m "Fixed a bug." <file_name> $> git commit -m "More debug information" <file_name> $> git push ## DON'T FORGET TO DO THIS!!
Always issue a git push command after committing all your changes
Additional information and examples:
Recording changes to the repository
Adding/Removing a file
Adding and removing files in CVS and git is also a very similar operation. Use the git rm and git add command in the same way you would use the cvs rm and cvs add command. Just remember to commit the change, followed by a git push. For example,
Adding a file:
$> git add <file_name> $> git commit -m "initial add of new file." <file_name> $> git push
Removing a file:
$> git rm <file_name> $> git commit -m "Removing obsolete file." <file_name> $> git push
Additional information and examples:
Start working here
git annex copy --to origin <file_name> |
Add a data file:
cvs |
cvs add <file_name> |
cvs commit <file_name> |
|
git |
git annex add <file_name> |
git commit <file_name> |
|
git push |
|
git annex copy --to origin <file_name> |
Remove data file:
cvs |
rm <file_name> |
cvs rm <file_name> |
|
cvs commit -m "Removing <file_name>" <file_name> |
|
git |
git rm <file_name> |
git commit -m "Removing <file_name>" <file_name> |
Undo 1 commit (before push):
git |
git reset --soft HEAD~1 |
Undo 2 commits:
git |
git reset --soft HEAD~2 |