# GIT
- 创建
- 本地修改
- 提交历史
- 分支与标签
- 更新与发布
- 合并与重置
- 撤销
- 工作区,版本库(暂存区-stage,分支-master)图
- 创建与合并分支图
- branches图
- git folw图
# 创建
复制一个已创建的仓库
$ git clone ssh://user@domain.com/repo.git
1
创建一个新的本地仓库
$ git init
1
# 本地修改
显示工作路径下已修改的文件:
$ git status
1
显示与上次提交版本文件的不同:
$ git diff
1
把当前所有修改添加到下次提交中:
$ git add .
1
把对某个文件的修改添加到下次提交中:
$ git add -p <file>
1
提交本地的所有修改:
$ git commit -a
1
提交之前已标记的修改:
$ git commit
1
附加消息提交:
$ git commit -m 'message here'
1
修改上次提交
请勿修改已发布的提交记录!
$ git commit --amend
1
# 提交历史
从最新提交开始,显示所有的提交记录(显示hash, 作者信息,提交的标题和时间):
$ git log
1
显示所有提交(仅显示提交的hash和message):
$ git log --oneline
1
显示某个用户的所有提交:
$ git log --author="username"
1
显示某个文件的所有修改:
$ git log -p <file>
1
谁,在什么时间,修改了文件的什么内容:
$ git blame <file>
1
# 分支与标签
列出所有的分支:
$ git branch
1
切换分支:
$ git checkout <branch>
1
基于当前分支创建新分支:
$ git branch <new-branch>
1
基于远程分支创建新的可追溯的分支:
$ git branch --track <new-branch> <remote-branch>
1
删除本地分支:
$ git branch -d <branch>
1
给当前版本打标签:
$ git tag <tag-name>
1
# 更新与发布
列出对当前远程端的操作:
$ git remote -v
1
显示远程端的信息:
$ git remote show <remote>
1
添加新的远程端:
$ git remote add <remote> <url>
1
下载远程端版本,但不合并到HEAD中:
$ git fetch <remote>
1
下载远程端版本,并自动与HEAD版本合并:
$ git remote pull <remote> <url>
1
将远程端版本合并到本地版本中:
$ git pull origin master
1
将本地版本发布到远程端:
$ git push remote <remote> <branch>
1
删除远程端分支:
$ git push <remote> :<branch> (since Git v1.5.0)
or
git push <remote> --delete <branch> (since Git v1.7.0)
1
2
3
2
3
发布标签:
$ git push --tags
1
# 合并与重置
将分支合并到当前HEAD中:
$ git merge <branch>
1
将当前HEAD版本重置到分支中:
请勿重置已发布的提交!
$ git rebase <branch>
1
退出重置:
$ git rebase --abort
1
解决冲突后继续重置:
$ git rebase --continue
1
使用配置好的merge tool 解决冲突:
$ git mergetool
1
在编辑器中手动解决冲突后,标记文件为已解决冲突
$ git add <resolved-file>
$ git rm <resolved-file>
1
2
2
# 撤销
放弃工作目录下的所有修改:
$ git reset --hard HEAD
1
移除缓存区的所有文件(i.e. 撤销上次git add):
$ git reset HEAD
1
放弃某个文件的所有本地修改:
$ git checkout HEAD <file>
1
重置一个提交(通过创建一个截然不同的新提交)
$ git revert <commit>
1
将HEAD重置到上一次提交的版本,并放弃之后的所有修改:
$ git reset --hard <commit>
1
将HEAD重置到上一次提交的版本,并将之后的修改标记为未添加到缓存区的修改:
$ git reset <commit>
1
将HEAD重置到上一次提交的版本,并保留未提交的本地修改:
$ git reset --keep <commit>
1