$ git status # check the status $ git diff # check changes $ git add . # track all changed files $ git add <file> # track the specified file $ git mv <old> <new> # rename file $ git rm <file> # delete file $ git commit -m "commit msg"# commit all changed files $ git commit --amend # amend the last commit
Check commit history
1 2 3
$ git log# show commit logs $ git log -p <file> # show commit logs of <file> $ git blame <file> # show what revision and author last modified each line of a file
Undo
1 2 3
$ git reset --hard HEAD # undo all uncommitted contents in the work directory $ git checkout HEAD <file> # undo the changed contents of an uncommitted file $ git revert <commit> # revert specified commit
Branch and Tag
1 2 3 4 5 6 7
$ git branch # show all local branches $ git checkout <branch/tag> # git checkout to the branch/tag $ git branch <new-branch> # create a new branch $ git branch -d <branch> # delete the local branch $ git tag # show all local tags $ git tag <tag-name> # create tag based on the latest commit $ git tag -d <tag-name> # delete tag
Merge and rebase
1 2
$ git merge <branch> # merge <branch> to the current branch $ git rebase <branch> # rebase <branch> to the current branch
Remote
1 2 3 4 5 6 7 8 9
$ git remote -v # check remote repository information $ git remote show <remote> # show specified remote repository information $ git remote add <remote> <url> # add remote repository
$ get fetch <remote> # fetch code from the remote repository $ git pull <remote> <branch> # pull and quick merge $ git push <remote> <branch> # push and quick merge $ git push <remote> :<branch/tag-name> # delete remote branch or tag $ git push --tags # push all tags