#create a new dir to store the gitreso mkdir <dirname> git init # look all resouce ls -a #create a new git reso in the present dir git init <newdirname>
git workspace and file status
git workspace
file status
untrack *the new created file
unmodified *the unchanged git file
modified *the changed git file but haven’t add into the Staging Area
staged *the changed git file and already add into the SA
1 2 3 4 5 6 7 8 9 10
# present gitdir status git status # add file to AS git add <filename> # add present dir's all changed file to AS # '.' means to present dir git add . # add all the type of files is .txt to AS git add *.txt
1 2 3 4
# commit the files in AS git commit -m "<title>" # into Vim mode to commit files in AS git commit
1 2
#finish add and commit at onec git commit -am ""
1 2 3 4
#search past commit record git log #brief commit record git log --oneline
git reset
1 2 3 4 5 6 7 8 9 10 11 12
git log --online
git reset --soft <commit_hash> git reset --hard <commit_hash> git reset --mixed <commit_hash> # roolback to last version git reset --sofe HEAD^ # roolback roolback to the last version ## to get the version number git reflog ## roolback roolback to the last version gir reset --hard <commit_hash>
git diff
usually use the GUI tools
but sometimes we need to learn about it to run some machine which without GUI tools
#compare diffrences between the Working directory and Staging area git diff #compare diffrences between the Working directory and local repository git diff HEAD #compare diffrences between the Staging area and local repository git diff --cached #compare diffrences between two version file git diff <commit_hash1> <commit_hash2> ## two symbol # 'HEAD' means present version # '~' or '^' means last version # so we can do like this to ## git diff HEAD~ HEAD git diff HEAD^ HEAD # and we can input a number behind the ~ which means last N verision git diff HEAD~2 HEAD # check specific files diff git diff HEAD~2 HEAD <filename>
rm files
1 2 3 4 5 6 7 8 9 10 11 12
#just remove the files in Working dirctory but doesn's remove in AS rm <filename> #so we need git add . to update the diff into AS git add . # or we can rm directly by use git rm git rm <filename> # rm files in local repository but don't rmin WD git rm --cached <filename> #at last we need to commit to updata diff into local repository git commit -m ""