Git 常用命令

Git · forecho · 于 6年前 发布 · 3100 次阅读

git-flow

http://danielkummer.github.io/git-flow-cheatsheet/index.zh_CN.html

http://nvie.com/posts/a-successful-git-branching-model/

创建分支

git  branch [分支名]

切换分支

git checkout [分支名]

回到指定版本号

git reset 版本号

本地覆盖服务器 强行提交

git push origin master -f

或者

git push -f

把其他分支合并到本分支

git merge --no-ff <branch-name>

git 提交分支到服务器

git checkout -b your_branch
git push <remote-name> <branch-name>

查看远程分支

git branch -r

查看所有分支

git branch -a

拉取远程分支并且使用

git pull origin other-branch
git fetch && git checkout other-branch

删除分支

git branch -d <branch-name>
git push origin :<branch-name>

查看当前 Git 密钥

cat ~/.ssh/id_rsa.pub

将HTTPS修改为SSH(不要每次GIT PUSH都输入密码)

更新 remote URL

git remote set-url origin git@coding.net:xxx/yyy.git

撤销提交

git reset HEAD^

直接重写 commit

git commit --amend

提交后发现忘记了暂存某些需要的修改,可以像下面这样操作:

$ git commit -m 'initial commit'
$ git add forgotten_file
$ git commit --amend

添加模块代码

git submodule init
git submodule update 

GitHub

github commit 内容带上「 closes #23」 会自动关闭 ID 为23的 issues

最后欢迎大家再补充。

本文由 forecho 创作,采用 知识共享署名 3.0 中国大陆许可协议 进行许可。 可自由转载、引用,但需署名作者且注明文章出处。

共收到 2 条回复 Git
fqbqing#16年前 1 个赞
git cherry-pick  提交

补充一个

forecho#26年前 0 个赞

@fqbqing #1楼 你这个命令还真没用过,如果你用过,可以说一下使用场景和如何使用吗?

添加回复 (需要登录)
需要 登录 后方可回复, 如果你还没有账号请点击这里 注册