some buildin command also can be ask git <verb> -h
git clone
to set an anther name of the repository by
1
git clone URL newname
git add
to track file
1
git add files
git stataus
1 2
git status #to show the repository status, filse be tracked or staged git status -s #--short
gitignore
the rules for the patterms:
bland line or lines starting with # are ignored
lines start with slash/ will avoid recursivity
lines end with slash/ to specify a directory
lines start with point! to be negated a pattern
standard glob patterns works
* to matches zero to more characters; [abs\] to matches characters inside the brackets ? to matches a single charater ** to matches nested directories [0-9] to matches any character between them
git diff
1 2
git diff # to show the difference between changed but not yet staged files git diff --staged #--cached to show the difference between staged and the last commited
git commit
1 2 3 4 5
git commit # to commit the staging area git commit -m "message"# git commit -a # to skip the staging area git commit --amend #to commit the staging area files to the latstest commit or rewrite commit message
git rm
1 2 3
git rm filse # to remove the staged filse from staging area and working directory git rm -f filse # to remove tracked but not yet added filse git rm --cached # to remove filse only from staging area but not delete from working directory
git mv
1 2 3 4 5
git mv fromfile tofile # to move filse or remane file # equl to the following command mv fromfile tofile git rm fromfile git add tofile
git log
1 2 3 4 5 6 7 8 9 10 11 12 13 14
git log# to show all commits information , auther, time, sorted by time git log -p -2 #--patch to show the difference introduced in each commit, limit the number of commit git log --stat#to show abbreviated stats git log --pretty=oneline #also short, full, fuller, to show the output in specifical format git log --pretty=format"%n - %an, %ar : %s"#to format output git log --graph #to add a nice ASCII graph showing your branch and merge historyg
git log --since=2.weeks git log --until=2.weeks git log -S string #to show some commits that add/remove the paticular string #there are also some option that I cant record, I can refer in [gitpro](https://git-scm.com/book/zh/v2/Git-%E5%9F%BA%E7%A1%80-%E6%9F%A5%E7%9C%8B%E6%8F%90%E4%BA%A4%E5%8E%86%E5%8F%B2)
git log --decorate #show each branch point which object git log --oneline --decorate --graph --all #output the commit history, branch pointer and diverged
git reset
1 2 3 4
git reset HEAD <file> # to reset file to the lastest commited version, in anther way , to clear the file from staging area git reset --soft <commit> # to redo the lastest commit but keep the modified git reset --hard <commit> # to back to the commit status in staging area and work directory, and do not keey the modified
git checkout
1 2 3 4 5
git checkout -- <file> # to discard changes in wording diretory git checkout 2.2.0 # check out tags git checkout <branch> #check out the branch git switch <branch> git checkout -b <newbranchname> #create and checkout the branch
git restore
1 2
git restore --staged <file> # to unstage the file but not discard modification git restore <file> # to dicard the modification of the file
git remote
1 2 3 4 5 6
git remote # to show the remote servers name, origin git remote -v # to show the URLs that your can pull and fetch git remote add <shortname> <url> # to add a remote repository and give it a shortname git remote show <remote> # to show detailed imformation of the remote git remote rename oldname nowname # to rename the remote git remote remove <remote> # to remove the remote repository
git fetch
1
git fetch <remote> # fetch remote repository by URL or shortname, and the default name of cloned repository is origin
git push
1 2 3 4 5
git push origin master # to push master branch to upstream(remote) git push origin v1.5 # push tag to remote git push origin --tag # push all tags to remote git push origin :refs/tags/v1.4 #push null value before the colon: to the remote git push origin --delete <tagname> # delete the tag
git tag
1 2 3 4 5 6 7
git tag # to list existing tags git tag -l "v1.8*"#--list to list particular tags git tag v1.0.0 -lw # a lightweight tag, just a pointer git tag -a v1.0.0 -m "First stable release"#Annotated tag, attach other information git show v1.0.0 # to show the imformation of the tag and commit git tag -a v1.2 9fceb02 # to add a tag to a commit git tag -d <tagname> # to delete a lightwight tag
branch
they are three object each commit object contain there parent
1 2 3 4
git branch #list all branch git branch newbranchname #create a new branch git branch -d <branch> #delete the branch git branch --merged #filter the merged branch, and --no-merged
git merge
1
git merge <bemergedbranch> #to merge a branch
if there is any conflict in the merge, you can check by running git status, and then modify the file . after that, run git add on each file to mark it as resolved