Git 速查表

2018-03-30  本文已影响0人  曼巴童鞋

Git命令大致分为这几个模块:

序号 模块 功能
1 CREATE 关于创建的
2 LOCAL CHANGES 关于本地改动方面的
3 COMMIT HISTORY 关于提交历史的
4 BRANCHES & TAGS 关于分支和标签类的
5 UPDATE & PUBLISH 关于更新和发布的
6 MERGE & REBASE 关于分支合并类的
7 UNDO 关于撤销类的
8 SUBMODULE 关于子模块

CREATE

git clone ssh://user@domain.com/repo.git
git init

LOCAL CHANGES

git status
git diff
git diff <fileName>
git add -A
git add .
git add -u
git add -p <file>
git commit -a
git commit
$ git commit --amend

COMMIT HISTORY

git log
git log -p <file>
git blame <file>

BRANCHES & TAGS

git branch -a
git branch -av
git checkout <branch>
git branch <new-branch> <old-branch>
git checkout -b <new-branch>
git branch -d  <branch>
git push origin --delete <branch>
git tag
git tag <tag-name>
git tag -d <tag-name>
git push origin tagname
git push origin --tags

UPDATE & PUBLISH

git remote -v
git remote show <remote>
git remote add <shortname> <url>
git fetch <remote>
git pull <remote> <branch>
git push <remote> <branch>
git branch -dr <remote/branch>
git push --tags

MERGE & REBASE

git merge <branch>
 git rebase <branch>
git rebase --abort
git rebase --continue
git mergetool
git add <resolved-file>
git rm <resolved-file>

UNDO

git reset --hard HEAD
git reset --hard HEAD^
git checkout HEAD <file>
git revert <commit>
git reset --hard <commit>
git reset <commit>
git reset --keep <commit>

SUBMODULE

git submodule add https://github.com/xxxxxx/Test
// 方法一
 git clone https://github.com/xxxxxx/MainProject    
 cd MainProject                //  子模块目录Test没有文件
 cd Test
 git submodule init
 git submodule update     // 执行完后就有子模块的代码了

//方法二
// 自动更新子模块中的代码
 git clone --recurse-submodules https://github.com/xxxxxx/MainProject
// 需使用 `--allow-unrelated-histories`
// 将远程master项目合并到你本地项目
 git pull origin master --allow-unrelated-histories

原文链接:http://blog.kesixin.xin/article/61

上一篇 下一篇

猜你喜欢

热点阅读