Git小抄

生存必备

git init
git add <file1> <file2>
git add .
git add -A
git commit -m "xxxxx"
git log or git log --pretty=oneline
git status
git diff
git diff HEAD -- <file> 查看工作区文件和最新版本的区别

分支

git branch list all branch
git checkout -b dev create a new branch and checkout it, or

git branch dev
git checkout dev

git merge dev merge to master and del
git branch -d dev del dev

忽略已提交的文件

  1. git rm -cached <file>
  2. update .gitignore and commit it

版本回退

git reset --hard <commit_id>(HEAD~1)
git reflog 查看历史命令

撤销修改

git checkout -- <file> 用repo的文件覆盖工作区的文件
git reset HEAD <file> unstage, 从HEAD复制文件到index

删除文件

git rm <file>
git commit -m "del <file>"

修改最后一次提交的说明信息

git add <file> # optional
git commit --amend -m "xxx"

tag

git tag 列出tag
git show <tag name>
git tag <tag name> 在当前commit上打标签
git tag <tag name> <commit_id> 在指定的commit上打标签
git tag -a <tag name> [-m "xx" | <commit_id>] 带说明(annotation)的tag
git tag -d <tag name>

原文地址:https://www.cnblogs.com/whenyd/p/8427762.html