Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
Introduction
Git is a popular free and open-source distributed version control tool.
Basic commands
Initialize a git repo
1
git init
Add file to git repo
1
git add <paths>
Add all files
1
git add .
Undo add
1
git reset
Reset a single file in the index
1
git reset -- <file>
Undo last two commits
1
git reset --hard HEAD^
Reset to some commit
1
git reset --hard commit id
Restore file
1
git checkout -- <file>
Record changes to repo
1
git commit -m "msg"
Show the working tree status
1
git status
Show changes
1
git diff
Changes in some file in the working tree since last commit
1
git diff HEAD -- <file>
Show commit logs
1
git log
Pretty-print the contents of the commit logs in a given format
1
git log --pretty=oneline
Draw graph of the commit history
1
git log --graph
Show only partial prefix
1
git log --graph --pretty=oneline --abbrev-commit
Show last commit log
1
git log -1
Show reference logs
1
git reflog
Remove files from the working tree and from the index
1
git rm <file>
Show branches
1
git branch
Create a branch
1
git branch <branchname>
Switch to a branch
1
git checkout <name>
Create and switch to a branch
1
git checkout -b <name>
Create and switch to a branch and relate it to a remote repo branch
近期评论