1. init git will initialise a git project.
2. Git project may have three parts:
3. git status will give you:
On branch master
Initial commit
nothing to commit (create/copy files and use "git add" to track)
4. create one file of any format and type in git status again. This will give you:
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
test.txt
nothing added to commit but untracked files present (use "git add" to track)
5. then, you can do: git add test.txt to keep track of this file.
$ git add test.txt
$ git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: test.txt
6. suppose you have made changes to your file (staging area). Then you want to check differences between the working directory and the staging area with. So you do: nano test.txt and ofc, type something in. and Then save, and do: git diff test.txt:
$ git diff test.txt
diff --git a/test.txt b/test.txt
index e69de29..daa7ea7 100644
--- a/test.txt
+++ b/test.txt
@@ -0,0 +1 @@
+somethingsometighnseomthing
7. You have identified the difference between the new version of test.txt and the old version of test.txt. To apply the changes, you can do: git add test.txt again.
8. A commit is the last step in our Git workflow. A commit permanently stores changes from the staging area inside the repository. you do: git commit -m "Commit message", and the convention for the commit messages is:
if you do that, bash is going to give you:
$ git commit -m "test complete"
[master (root-commit) 7eed22f] test complete
Committer: *******************************>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name "Your Name"
git config --global user.email [email protected]
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
1 file changed, 1 insertion(+)
create mode 100644 test.txt
9. if you are curious about your commits log, you can do: git log. This is going to show your all the versions of your work. For example, if you have modified your test.txt once more and then did the same thing over and typed git log, you are going to get:
$ git log
commit 8a146d6e3e4d29a35bb5ea6c258d51445a099db2
Author: ***** <*****.local>
Date: Fri Apr 7 18:01:13 2017 +0800
another change
commit 7eed22f0fb2862581a83dbefb25bcb44d28450ba
Author: ***** <*****.local>
Date: Fri Apr 7 17:57:23 2017 +0800
test complete
10. git show HEAD will show you the information about the head commit (the commit you are currently working on is the head commit):
$ git show HEAD
commit 8a146d6e3e4d29a35bb5ea6c258d51445a099db2
Author: ***** <*****.local>
Date: Fri Apr 7 18:01:13 2017 +0800
another change
diff --git a/test.txt b/test.txt
index daa7ea7..38eadce 100644
--- a/test.txt
+++ b/test.txt
@@ -1 +1,2 @@
somethingsometighnseomthing
+asfwefw@@@@@@@@
11. you can rewrite on the file that you are currently working on with the last version saved in git. Here's how:
git checkout HEAD filename
$ git diff test.txt
diff --git a/test.txt b/test.txt
index 38eadce..261c7b5 100644
--- a/test.txt
+++ b/test.txt
@@ -1,2 +1,3 @@
somethingsometighnseomthing
asfwefw@@@@@@@@
+line to be deleted soon
** at ******** in ~/Desktop/dummy on master*
$ git checkout HEAD test.txt
** at ******** in ~/Desktop/dummy on master*
$ git diff test.txt
as seen, the last git diff test.txt command will not give anything new, because test.txt has gone back to its previous version:
$ cat test.txt
somethingsometighnseomthing
asfwefw@@@@@@@@
12. you can actually add more than two files with git add:
**** at **** in ~/Desktop/dummy on master*
$ nano test.txt
**** at **** in ~/Desktop/dummy on master*
$ nano anotherFileToAdd
**** at **** in ~/Desktop/dummy on master*
$ mv anotherFileToAdd anotherFileToAdd.txt
**** at **** in ~/Desktop/dummy on master*
$ git add anotherFileToAdd.txt test.txt
**** at **** in ~/Desktop/dummy on master*
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: anotherFileToAdd.txt
modified: test.txt
13. if you have made a mistake but have added it by using git add, you can undo(unstage) it using git reset HEAD filename:
**** at **** in ~/Desktop/dummy on master*
$ git reset HEAD anotherFileToAdd.txt
**** at **** in ~/Desktop/dummy on master*
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: test.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
anotherFileToAdd.txt
14. Going back to previous versions: git reset (first 7 Characters of SHA of the version that you wanna go back to)
**** at **** in ~/Desktop/dummy on master*
$ git log
commit 8a146d6e3e4d29a35bb5ea6c258d51445a099db2
Author: ***** <*****.local>
Date: Fri Apr 7 18:01:13 2017 +0800
another change
**** at **** in ~/Desktop/dummy on master*
Author: ***** <*****.local>
Date: Fri Apr 7 17:57:23 2017 +0800
test complete
**** at **** in ~/Desktop/dummy on master*
$ git reset 7eed22f
Unstaged changes after reset:
M test.txt
$ git log
commit 7eed22f0fb2862581a83dbefb25bcb44d28450ba
Author: ***** <*****.local>
Date: Fri Apr 7 17:57:23 2017 +0800
test complete
notice that your latest log is now the previous version that you were looking for. To make it simple, you are rewinding the project back to where you want.
2. Git project may have three parts:
- A Working Directory: where you'll be doing all the work: creating, editing, deleting and organizing files
- A Staging Area: where you'll list changes you make to the working directory
- A Repository: where Git permanently stores those changes as different versions of the project
3. git status will give you:
On branch master
Initial commit
nothing to commit (create/copy files and use "git add" to track)
4. create one file of any format and type in git status again. This will give you:
On branch master
Initial commit
Untracked files:
(use "git add <file>..." to include in what will be committed)
test.txt
nothing added to commit but untracked files present (use "git add" to track)
5. then, you can do: git add test.txt to keep track of this file.
$ git add test.txt
$ git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: test.txt
6. suppose you have made changes to your file (staging area). Then you want to check differences between the working directory and the staging area with. So you do: nano test.txt and ofc, type something in. and Then save, and do: git diff test.txt:
$ git diff test.txt
diff --git a/test.txt b/test.txt
index e69de29..daa7ea7 100644
--- a/test.txt
+++ b/test.txt
@@ -0,0 +1 @@
+somethingsometighnseomthing
7. You have identified the difference between the new version of test.txt and the old version of test.txt. To apply the changes, you can do: git add test.txt again.
8. A commit is the last step in our Git workflow. A commit permanently stores changes from the staging area inside the repository. you do: git commit -m "Commit message", and the convention for the commit messages is:
- Must be in quotation marks
- Written in the present tense
- Should be brief (50 characters or less) when using -m
if you do that, bash is going to give you:
$ git commit -m "test complete"
[master (root-commit) 7eed22f] test complete
Committer: *******************************>
Your name and email address were configured automatically based
on your username and hostname. Please check that they are accurate.
You can suppress this message by setting them explicitly:
git config --global user.name "Your Name"
git config --global user.email [email protected]
After doing this, you may fix the identity used for this commit with:
git commit --amend --reset-author
1 file changed, 1 insertion(+)
create mode 100644 test.txt
9. if you are curious about your commits log, you can do: git log. This is going to show your all the versions of your work. For example, if you have modified your test.txt once more and then did the same thing over and typed git log, you are going to get:
$ git log
commit 8a146d6e3e4d29a35bb5ea6c258d51445a099db2
Author: ***** <*****.local>
Date: Fri Apr 7 18:01:13 2017 +0800
another change
commit 7eed22f0fb2862581a83dbefb25bcb44d28450ba
Author: ***** <*****.local>
Date: Fri Apr 7 17:57:23 2017 +0800
test complete
10. git show HEAD will show you the information about the head commit (the commit you are currently working on is the head commit):
$ git show HEAD
commit 8a146d6e3e4d29a35bb5ea6c258d51445a099db2
Author: ***** <*****.local>
Date: Fri Apr 7 18:01:13 2017 +0800
another change
diff --git a/test.txt b/test.txt
index daa7ea7..38eadce 100644
--- a/test.txt
+++ b/test.txt
@@ -1 +1,2 @@
somethingsometighnseomthing
+asfwefw@@@@@@@@
11. you can rewrite on the file that you are currently working on with the last version saved in git. Here's how:
git checkout HEAD filename
$ git diff test.txt
diff --git a/test.txt b/test.txt
index 38eadce..261c7b5 100644
--- a/test.txt
+++ b/test.txt
@@ -1,2 +1,3 @@
somethingsometighnseomthing
asfwefw@@@@@@@@
+line to be deleted soon
** at ******** in ~/Desktop/dummy on master*
$ git checkout HEAD test.txt
** at ******** in ~/Desktop/dummy on master*
$ git diff test.txt
as seen, the last git diff test.txt command will not give anything new, because test.txt has gone back to its previous version:
$ cat test.txt
somethingsometighnseomthing
asfwefw@@@@@@@@
12. you can actually add more than two files with git add:
**** at **** in ~/Desktop/dummy on master*
$ nano test.txt
**** at **** in ~/Desktop/dummy on master*
$ nano anotherFileToAdd
**** at **** in ~/Desktop/dummy on master*
$ mv anotherFileToAdd anotherFileToAdd.txt
**** at **** in ~/Desktop/dummy on master*
$ git add anotherFileToAdd.txt test.txt
**** at **** in ~/Desktop/dummy on master*
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
new file: anotherFileToAdd.txt
modified: test.txt
13. if you have made a mistake but have added it by using git add, you can undo(unstage) it using git reset HEAD filename:
**** at **** in ~/Desktop/dummy on master*
$ git reset HEAD anotherFileToAdd.txt
**** at **** in ~/Desktop/dummy on master*
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: test.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
anotherFileToAdd.txt
14. Going back to previous versions: git reset (first 7 Characters of SHA of the version that you wanna go back to)
**** at **** in ~/Desktop/dummy on master*
$ git log
commit 8a146d6e3e4d29a35bb5ea6c258d51445a099db2
Author: ***** <*****.local>
Date: Fri Apr 7 18:01:13 2017 +0800
another change
**** at **** in ~/Desktop/dummy on master*
Author: ***** <*****.local>
Date: Fri Apr 7 17:57:23 2017 +0800
test complete
**** at **** in ~/Desktop/dummy on master*
$ git reset 7eed22f
Unstaged changes after reset:
M test.txt
$ git log
commit 7eed22f0fb2862581a83dbefb25bcb44d28450ba
Author: ***** <*****.local>
Date: Fri Apr 7 17:57:23 2017 +0800
test complete
notice that your latest log is now the previous version that you were looking for. To make it simple, you are rewinding the project back to where you want.