...
There is a variety of good information about Git available online, including:including The official Git documentation, which includes both a tutorial and a complete reference manual with links to individual subcommand documentation.
...
Getting Started
Getting help
...
This initializes the repository. Next, create two files to add the existing files to the repository:
...
to the repo
Code Block |
---|
$ cat > file1.py << EOF
cat > file1.py << EOF
> #!/usr/bin/env python
> print ("This is file1.py")
> EOF
$ cat > file2.py << EOF
> #!/usr/bin/env python
> print ("This is file2.py")
> EOF |
What files added? status
Code Block |
---|
$ git status
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
file1.py
file2.py
nothing added to commit but untracked files present (use "git add" to track)
|
Adding files
The git add
command schedules files to be committed to the repository.
Code Block |
---|
$ git add file1.py 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.
Use the git reset
command (if you want ) to "undo" an add operation:
...
You may also commit a subset of modified files by specifying paths on the
command line:
Code Block |
---|
$ git commit [path/to/modified/file] -m 'brief message of the recent change' |
Managing Files
Renaming files
...
Code Block |
---|
$ git rm file1.py |
What's
...
modified: status
Use git status to see a list of modified files:
Code Block |
---|
$ cat > file2.py << EOF
> #!/usr/bin/env python
> print ("This is file2.py")
> print ("New line ")
> EOF |
Code Block |
---|
$ git status |
The output of git status
will look something like this:
Code Block |
---|
$ git status # On branch master #Changes Changednot butstaged notfor updatedcommit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: version-controlfile2.rstpy # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # examples/ no changes added to commit (use "git add" and/or "git commit -a") |
The files listed as "changed but not updated" are files that you have modified but not yet added to the repository. "Untracked files" are files that have not previously been added to the repository.
...
Code Block |
---|
$ git diff diff --git a/version-controlfile2.rstpy b/version-controlfile2.rstpy index e518192b9a7216..b1c519a6b6dcff 100644 --- a/version-controlfile2.rstpy +++ b/version-controlfile2.rstpy @@ -2431,62 +2431,343 @@ commit`` to commit them to the (local) repository:: Using git: What's changed? ========================== +Use ``git status`` to see a list of modified files:: + + git status + +.. container:: handout + + The output will look something like this:: + #!/usr/bin/env python print ("This is file2.py") +print ("New line ") |
You can also use git diff to see the changes between arbitrary revisions of your project:
Changes in working copy vs. previous commit:
Code Block git diff <commit>
...
Changes between two previous commits:
Code Block git diff <commit1> <commit2>
Working With Remote Repositories
Cloning
...
Remote Repository
Use the git clone
command to check out a working copy of a remote repository:
...
To resolve the conflict manually:
- Edit the conflicting files as necessary.
To discard your changes (and accept the remote repository version):
- run
git checkout --theirs README
To override the repository with your changes:
- run
git checkout --ours README
When you complete the above tasks:
- add the files with
git add
- commit the changes with
git commit
.
Log, Tags, and Branches
Viewing history
...
Git has explicit support for tagging and branching.
git tag
manipulates tagsgit branch
andgit checkout
manipulate branches
Tags
Create a tag:
Code Block |
---|
$ git tag [-a] TAGNAME |
...
Code Block |
---|
$ git checkout master $ git merge dev Updating 1288ed3..33e4a4c Fast-forward version-control.rst | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) |
The Git Index
Git is not really just like Subversion (or most other version control solutions). That's mainly because of the git "index".
- The index is a staging area between your working copy and your local repository.
git add
adds files to the indexgit commit
commits files from the index to the repository.
The diff commands uses the index:
git diff
is the difference between your working copy and the index.git diff HEAD
is the difference between your working copy and the local repository.git diff --cached
is the difference between the index and the local repository.
Refer back to this illustration if you get confused: