: a super short documentation
Git is a distributed revision control system, it allows to:
- keep track of the changes.
- find out what has been changed.
- store the project at desired moments in time (i.e. perform backups - produce project versions).
- recover an earlier version.
To do so, Git stores the different versions of your project in a repository located in your project directory.
Installation
Visit the website http://git-scm.com
to download Git and find the complete documentation.
During the installation, select Git from Git bash only. When this is done,
for Mac/Linux:
launch a Terminal.
for Windows:
menu → Git → Git Bash
Create a Git account
- git config --global user.name "Alex Dumas"
- git config --global user.email ”alex@dumas.fr”
Git commands
initialize Git
Go to the project directory using Terminal/Powershell:
- cd project
- git init
The last command will create a hidden Git repository.
First backup (commit)
The first commit is done in 2 steps:
- git add .
- git commit -m ”first comments”
The first command sends the files from the Working area to the Staging area.
The second command sends the files from the Staging area to the Repository.
Next commits
- git commit -am ”new comments”
Useful commands
Check the difference between the working copy and the repository.
- git status
Get commit history
- git log
Delete a Git project
- rm -rf .git
An Example
creation of a folder containing a very simple file:
- mkdir git-test
- cd git-test
- emacs file.txt
File.txt:
one line
Git initialization
- git init
Initialized empty Git repository in /Users/adumas/git-test/.git/
Git first commit
- git add .
- git commit -m "first commit: 1 text file"
[master (root-commit) 209f961] first commit: 1 text file
1 file changed, 1 insertion(+)
create mode 100644 file.txt
check the repository
- git log
commit 209f961f9c8cfaad8f5689d354faa240ee161f7b
Author: Alex Dumas "alex@dumas.fr"
Date: Sat May 16 17:27:06 2015 +0100
first commit: 1 text file
modification the text file
first line
second line
third line
check the difference between the working area and the repository:
- git diff file.txt
diff --git a/file.txt b/file.txt
index e3c0674..ae0d792 100644
--- a/file.txt
+++ b/file.txt
@@ -1 +1,3 @@
-one line
+first line
+second line
+third line
Commit the new file
- git commit -am "second commit: 3 lines"
[master e869c09] second commit: 3 lines
1 file changed, 3 insertions(+), 1 deletion(-)
Check the commits history
- git log
commit e869c09ec49f611828ac45d48a5ea1106a806ac4
Author: Alex Dumas "alex@dumas.fr"
Date: Sat May 16 17:28:57 2015 +0100
second commit: 3 lines
commit 209f961f9c8cfaad8f5689d354faa240ee161f7b
Author: Alex Dumas "alex@dumas.fr"
Date: Sat May 16 17:27:06 2015 +0100
first commit: 1 text file
Note that a tracking number is associated to each commit:
the first commit has the tracking number:
209f961f9c8cfaad8f5689d354faa240ee161f7b
the second commit has the tracking number:
e869c09ec49f611828ac45d48a5ea1106a806ac4
Now, let's go back to the first commit:
- git checkout 209f961f9c8cf -- file.txt
- # note that the full tracking number is not needed
Commit the new version
- git commit -am "third commit: going back to first commit"
Last check of the commits history
- git log
commit 7cd3dc1a4c2bf9a974231c666f0c5b9b0ae49987
Author: Alex Dumas "alex@dumas.fr"
Date: Sat May 16 17:30:34 2015 +0100
third commit: going back to first commit
commit e869c09ec49f611828ac45d48a5ea1106a806ac4
Author: Alex Dumas alex@dumas.fr
Date: Sat May 16 17:28:57 2015 +0100
second commit: 3 lines
commit 209f961f9c8cfaad8f5689d354faa240ee161f7b
Author: Alex Dumas alex@dumas.fr
Date: Sat May 16 17:27:06 2015 +0100
first commit: 1 text file
- keep track of the changes.
- find out what has been changed.
- store the project at desired moments in time (i.e. perform backups - produce project versions).
- recover an earlier version.
Installation
Visit the website http://git-scm.com to download Git and find the complete documentation. During the installation, select Git from Git bash only. When this is done, for Mac/Linux: launch a Terminal. for Windows: menu → Git → Git BashCreate a Git account
- git config --global user.name "Alex Dumas"
- git config --global user.email ”alex@dumas.fr”
Git commands
initialize Git
Go to the project directory using Terminal/Powershell:- cd project
- git init
First backup (commit)
The first commit is done in 2 steps:- git add .
- git commit -m ”first comments”
Next commits
- git commit -am ”new comments”
Useful commands
Check the difference between the working copy and the repository.- git status
- git log
- rm -rf .git
An Example
creation of a folder containing a very simple file:
- mkdir git-test
- cd git-test
- emacs file.txt
one line
Git initialization
- git init
Initialized empty Git repository in /Users/adumas/git-test/.git/
- git add .
- git commit -m "first commit: 1 text file" [master (root-commit) 209f961] first commit: 1 text file
1 file changed, 1 insertion(+)
create mode 100644 file.txt
- git log commit 209f961f9c8cfaad8f5689d354faa240ee161f7b
Author: Alex Dumas "alex@dumas.fr"
Date: Sat May 16 17:27:06 2015 +0100 first commit: 1 text file
first line
second line
third line
check the difference between the working area and the repository:
- git diff file.txt diff --git a/file.txt b/file.txt index e3c0674..ae0d792 100644 --- a/file.txt +++ b/file.txt @@ -1 +1,3 @@ -one line +first line +second line +third line
- git commit -am "second commit: 3 lines" [master e869c09] second commit: 3 lines
1 file changed, 3 insertions(+), 1 deletion(-)
- git log commit e869c09ec49f611828ac45d48a5ea1106a806ac4
Author: Alex Dumas "alex@dumas.fr"
Date: Sat May 16 17:28:57 2015 +0100
second commit: 3 lines
commit 209f961f9c8cfaad8f5689d354faa240ee161f7b
Author: Alex Dumas "alex@dumas.fr"
Date: Sat May 16 17:27:06 2015 +0100
first commit: 1 text file
- git checkout 209f961f9c8cf -- file.txt
- # note that the full tracking number is not needed
- git commit -am "third commit: going back to first commit"
- git log commit 7cd3dc1a4c2bf9a974231c666f0c5b9b0ae49987 Author: Alex Dumas "alex@dumas.fr" Date: Sat May 16 17:30:34 2015 +0100 third commit: going back to first commit commit e869c09ec49f611828ac45d48a5ea1106a806ac4 Author: Alex Dumas alex@dumas.fr Date: Sat May 16 17:28:57 2015 +0100 second commit: 3 lines commit 209f961f9c8cfaad8f5689d354faa240ee161f7b Author: Alex Dumas alex@dumas.fr Date: Sat May 16 17:27:06 2015 +0100 first commit: 1 text file