用戶信息配置
git congfig user.name "xxxx" --global
git config user.email "xxx@xx.com" -global
git config --list --local
git config --list --global
git config --list --system
複製代碼
初始化倉庫
cd <project-path>
git init
git init <project-path>
複製代碼
提交修改
git status
git add <file-name>
git add -u
git add --all
git add .
git add -p
git commit -m "<message>"
git commit -a -m "<message>"
git commit -am "<message>"
git commit --amend
git commit --amend --no-edit
複製代碼
查看提交歷史
git diff
git diff -- <file-name>
git diff --cached
git diff HEAD
git diff <commit-id> <commit-id>
git log
git log -<number>
git log -p
git log --stat
git log --oneline
git log --graph
git show
git show <commit-id>
git show --name-only <commit-id>
git reflog
複製代碼
文件刪除&安全重命名&忽略
git rm <file-name>
git rm --cached <file-name>
git mv <old-name> <new-name>
git clean
git clean -n
複製代碼
撤銷修改,代碼回滾
git checkout <file-name>
git checkout .
git checkout <commit-id> <file-name>
git reset <file-name>
git reset --soft <commit-id>
git reset --mixed <commit-id>
git reset --hard <commit-id>
git revert <commit-id>
git revert -n <commit-id>
git revet <start-id>...<end-id>
git revert --continue
git revert --quit
git revert --abort
複製代碼
分支
git branch
git branch -r
git branch -a
git branch -v
git branch <branch-name>
git checkout -b <branch-name>
git checkout <branch-name>
git checkout -
git branch -d <branch-name>
git branch -D <branch-name>
git merge <branch-name>
git merge --no-ff <branch-name>
git cherry-pick <commit-id>
git cherry-pick <branch-name>
git cherry-pick <start-comm-id>...<end-commit-id>
挑選連續多個提交(左閉右閉,包括start-commit)
git cherry-pick <start-commid-id>^...<end-commit-id>
git cherry-pick --continue
git cherry-pick --quit
git cherry-pick --abort
複製代碼
打上Tag
git tag
git tag -l <tag-name>
git tag --points-at <commit-id>
git show <tag-name>
git show-ref --tags
git tag <tag-name>
git tag <tag-name> <commit-id>
git tag -a <tag-name> -m <message>
git tag -d <tag-name>
複製代碼
緊急加塞,使用stash
git stash
git stash save <message>
git stash -u
git stash -a
git stash list
git show stash@{<number>}
git stash apply
git stash apply <number>
git stash pop
git stash drop
git stash drop <number>
git stash clear
複製代碼
變基
git rebase <branch-name>
git rebase -i <commit-id
複製代碼
遠程倉庫
git clone <url>
git clone <url> <new-name>
git remote add <remote-name> <remote-url>
git remote -v
git remote remove <remote-name>
git remote rename <old-remote-name> <new-remote-name>
git push <remote-name> <branch-name>
git push <remote-name> <tag-name>
git push <remote-name> --tags
git fetch
git pull
git pull --rebase
複製代碼
更多文章