...
Code Block |
---|
$ git add file1.cpy file2.py.c |
Unlike Subversion, if you modify a file you (generally) need to git add that file in order to make the changes part of the next commit.
...
Code Block |
---|
$ git rm file1.cpy |
What's changed: status
Use git status to see a list of modified files:
...
The command git clone
will clone the remote repository to a new directory in your current directory named after the repository, unless you explicitly provide a name with the DIRECTORY argument.
This is analogous to Subversion's checkout operation.
You can only clone the top-level repository; unlike Subversion, git does not allow you to clone individual subtrees.
Updating your working copy
Use git pull
to update your local repository from the remote repository and merge changes into your working copy:
...
If you attempt to push to a repository that is newer than your working copy you will see an error similar to the following:
Code Block |
---|
$ git push To dottiness.seascode.harvard.edu:repos/myproject ! [rejected] master -> master (non-fast forward) error: failed to push some refs to 'dottinesscode.seas.harvard.edu:repos/myproject' To fix this, run git pull and deal with any conflicts. |
...
Code Block |
---|
$ git pull remote: Counting objects: 5, done. remote: Compressing objects: 100% (3/3), done. remote: Total 3 (delta 2), reused 0 (delta 0) Unpacking objects: 100% (3/3), done. From /Users/testuser/projects/version-control-workshop/work/repo2repo 4245cb6..84f1112 master -> origin/master Auto-merging README CONFLICT (content): Merge conflict in README Automatic merge failed; fix conflicts and then commit the result. |
...
Code Block |
---|
$ git log commit 7c8c3e71893d7481fdd9c13ec8f53cb9c61fac50 Author: testuser lastname <testuser@seas<testuser@g.harvard.edu> Date: ThuTue MarSep 18 12:46:46 20102018 -0400 changed GNU to Microsoft commit 257f2f3ff44c2165c1182d3673a825fcadf121aa Author: testuser lastname <testuser@seas<testuser@g.harvard.edu> Date: ThuTue MarSep 18 12:46:46 20102018 -0400 made a change commit 99c4fb8f37e48284d79c7396aaf755b514d6a249 Author: testuser lastname <testuser@seas<testuser@g.harvard.edu> Date: ThuTue MarSep 18 12:46:45 20102018 -0400 made some changes commit 20cc63576f7c88541f5b9471e20f4d1c5f8afcb9 Author: testuser lastname <testuser@seas<testuser@g.harvard.edu> Date: ThuTue MarSep 18 12:46:45 20102018 -0400 initial import |
Tagging and branching
...
For example, you want to enhance your code with some awesome experimental code. You create a new seas-workshop-dev branch "dev" branch and switch to it:
Code Block |
---|
$ git checkout -b seas-workshop-dev
|
You make some changes, and when things are working you commit your branch:
...
Code Block |
---|
$ git checkout master
$ git merge seas-workshop-dev
Updating 1288ed3..33e4a4c
Fast-forward
version-control.rst | 2 ++
1 files changed, 2 insertions(+), 0 deletions(-)
|
...