工作中我最常用的 GIT 命令*
git stash
git stash pop
git stash list
git stash apply
git stash drop
git reset --hard + 版本号 回溯版本,版本号在commit的时候与master跟随在一起
git reflog 显示命令历史
git checkout -- <file> 撤销命令,用版本库里的文件替换掉工作区的文件。我觉得就像是Git世界的ctrl + z
git rm 删除版本库的文件
git branch 查看当前所有分支
git branch <分支名字> 创建分支
git checkout <分支名字> 切换到分支
git merge <分支名字> 合并分支
git branch -d <分支名字> 删除分支,有可能会删除失败,因为Git会保护没有被合并的分支
git branch -D + <分支名字> 强行删除,丢弃没被合并的分支
git merge --no-ff <分支名字> 合并分支的时候禁用Fast forward模式,因为这个模式会丢失分支历史信息
git check-ignore -v <file> 检查为什么Git会忽略该文件
配置 GIT
* git config --list
* git config [--global] user.name "[name]"
* git config [--global] user.email "[email address]"
仓库
* git init
$ git init [project-name]
* git clone [url]
增加/删除文件
$ git add [file1] [file2] ...
$ git add [dir]
* git add .
$ git add -p
$ git add -f <file>
$ git rm [file1] [file2] ...
$ git rm --cached [file]
$ git mv [file-original] [file-renamed]
代码提交
* git commit -m [message]
$ git commit [file1] [file2] ... -m [message]
$ git commit -a
$ git commit -v
$ git commit --amend -m [message]
$ git commit --amend [file1] [file2] ...
$ git commit --no-verify -m "commit"
撤销
* git checkout [file]
$ git checkout [commit] [file]
* git checkout .
* git reset [file]
$ git reset --hard
$ git reset [commit]
$ git reset --hard [commit]
$ git reset --keep [commit]
$ git revert [commit]
查看信息
* git status
* git log
$ git log --stat
$ git log -S [keyword]
$ git log [tag] HEAD --pretty=format:%s
$ git log [tag] HEAD --grep feature
$ git log --follow [file]
$ git whatchanged [file]
$ git log -p [file]
$ git log -5 --pretty --oneline
$ git shortlog -sn
$ git blame [file]
$ git diff
$ git diff --cached [file]
$ git diff HEAD
$ git diff [first-branch]...[second-branch]
$ git diff --shortstat "@{0 day ago}"
$ git show [commit]
$ git show --name-only [commit]
$ git show [commit]:[filename]
$ git reflog
远程同步
$ git fetch [remote]
$ git remote -v
$ git remote show [remote]
* git remote add [shortname] [url]
* git pull [remote] [branch]
$ git push [remote] [branch]
$ git push [remote] --force
$ git push [remote] --all
$ git push -u origin master
git push -f origin master
标签
$ git tag
$ git tag [tag]
$ git tag [tag] [commit]
$ git tag -d [tag]
$ git push origin :refs/tags/[tagName]
$ git show [tag]
$ git push [remote] [tag]
$ git push [remote] --tags
$ git checkout -b [branch] [tag]
分支
$ git branch
$ git branch -r
$ git branch -a
$ git branch [branch-name]
$ git checkout -b [branch]
$ git branch [branch] [commit]
$ git branch --track [branch] [remote-branch]
$ git checkout [branch-name]
$ git checkout -
$ git branch --set-upstream [branch] [remote-branch]
$ git merge [branch]
$ git cherry-pick [commit]
$ git branch -d [branch-name]
$ git push origin --delete [branch-name]
$ git branch -dr [remote/branch]
忽略
git update-index --assume-unchanged 你的文件路径
git update-index --no-assume-unchanged 你的文件路径
git rm -r --cached .