1. 远程仓库相关
1.1 创建远程仓库
$ git init --bare # 在远程环境下执行,需要先创建文件夹
1.2 添加远程仓库
$ git remote add <remote name> <remote url address>
1.3 推送本地分支到远程仓库(创建远程分支)
$ git push <remote name> <branch name>
1.4 获取远程仓库的改动
$ git fetch <remote name>
1.5 同步远程仓库的改动到本地分支
$ git merge <remote branch>
通常可以使用命令 git branch -a 查看远程分支
1.6 删除远程分支
$ gitt push --delete <remote name> <branch name>
1.7 删除本地存在但是远程不存在的那些分支
$ git remote prune <remote name>
1.8 查看远程信息
$ git remote show <remote name>
2. 提交相关
2.1 添加某个目录下的所有改动,包括新增/修改/删除
$ git add --all <dir>
2.2 查看两个提交之间的文件改动
$ git diff --stat <commit1> <commit2>
2.3 创建对应commit的新branch
$ git checkout -b <branch name> <commit/tag/brach_name>
2.4 提交一个空的commit
$ git commit --allow-empty
2.5 提交一个不含message的commit
$ git commit --allow-empty-message
2.6 生成一个空的提交的patch
$ git format-patch -1 --always <commit>
2.7 Git Rebase
$ git rebase -i <commit>
$ git rebase --continue
$ git rebase --abort
2.8 解决 git am 碰到的冲突
$ git am <patch>
$ git apply --reject <patch>
- 根据.rej文件解决冲突 -
$ git add <modify file>
$ git am --resolved
2.9 修改 AuthorDate
git commit --amend --date="<date>"
2.10 修改 CommitDate
GIT_COMMITTER_DATE="<date>" git commit --amend
2.11 修改 Author
git commit --amend --reset-author