Start your git following instructions below
Work dict, stage and master
| name | function |
|---|---|
| work dict | What you can see in your computer |
| stage | Keep your files temporarily |
| master | Keep your old version works |
Commands
-
Create your files
mkdir testto create a new directorycd testtouch hello.txtto create new filevi hello.txtto edit -
Start a new git
After find your work directory
git init -
Store your files
git add filenameorgit add .to add all your file in the current directory -
Check git status
git statusNow you can see your files have added
On branch master Initial commit Changes to be committed: (use "git rm --cached <file>..." to unstage) new file: color.txt new file: hello.txt new file: touch -
Check the difference
If you make some change in the file hello.text
git diffdifference between work dict and stagediff --git a/color.txt b/color.txt index d30c108..2e0df5d 100644 --- a/color.txt +++ b/color.txt @@ -1 +1 @@ -Red +Red, pinkgit diff --cacheddifference between stage and mastergit diff HEAD --difference between work dict and masterdiff --git a/color.txt b/color.txt index d30c108..2e0df5d 100644 --- a/color.txt +++ b/color.txt @@ -1 +1 @@ -Red +Red, pink -
Store what in your stage to master
git addwrites into stage,butgit commitwrites from stage to mastergit commit -m "1st submit"[master (root-commit) 39ebede] 1st submit 3 files changed, 2 insertions(+) create mode 100644 color.txt create mode 100644 hello.txt create mode 100644 touch -
To restore all those deleted files
git ls-files -d | xargs git checkout -- -
To remove the git from project directory
rm -rf .git -
Log
git logcommit 39ebededfa95f30b777bd1c257079d86fe824a6b (HEAD -> master) Author: yuliliclover <yuliliclover@gmail.com> Date: Sun Feb 25 00:38:10 2018 -0500 1st submit -
Cancel those in stage from being committed to master
I made change in two files, but just commit one to the master
git status -sM color.txt M hello.txt` git add .`
git statusOn branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: color.txt modified: hello.txtgit reset HEAD -- color.txtto cancel this commit to masterUnstaged changes after reset: M color.txtgit status -sM color.txt M hello.txtgit commit -m "change"[master 0cf29e4] change 1 file changed, 1 insertion(+), 1 deletion(-)git logAuthor: yuliliclover <yuliliclover@gmail.com> Date: Sun Feb 25 00:59:53 2018 -0500 change commit 39ebededfa95f30b777bd1c257079d86fe824a6b Author: yuliliclover <yuliliclover@gmail.com> Date: Sun Feb 25 00:38:10 2018 -0500 1st submit
-
Recover your last version from master to work dict
Very dangerous!!! You have to remember your last commit clearly!
git diffdiff --git a/color.txt b/color.txt index d30c108..b08fdac 100644 --- a/color.txt +++ b/color.txt @@ -1 +1 @@ -Red +Red, pink, blue diff --git a/hello.txt b/hello.txt index 8d6e1e9..716319a 100644 --- a/hello.txt +++ b/hello.txt @@ -1 +1 @@ -Hello World! Goodbye! +Hello World! Goodbye!jhdsoi[oaidhhcoiajiojeoijrgit checkout hello.txtonly recover this file from last commitgit diffdiff --git a/color.txt b/color.txt index d30c108..b08fdac 100644 --- a/color.txt +++ b/color.txt @@ -1 +1 @@ -Red +Red, pink, blue -
Revert to previous version
git reflogto see all your changes7780f1f (HEAD -> master) HEAD@{0}: commit: change2 39ebede HEAD@{1}: reset: moving to HEAD~1 0cf29e4 HEAD@{2}: commit: change 39ebede HEAD@{3}: commit (initial): 1st submitYou should keep the first number according to your commit msg
Say you want to return “change”
git reset --hard 0cf29e4HEAD is now at 0cf29e4 change