git push
git
用法
git push [-u] [--force-with-lease] <remote> <branch>把你的提交推到远端;--force 会覆盖远端分支,连别人推的提交都可能被抹掉,所以用 --force-with-lease,远端一动它就拒绝。
常用选项
| 选项 | 含义 |
|---|---|
| -u | set the upstream so later pushes need no arguments |
| --force-with-lease | force, but stop if the remote moved since your last fetch |
| -f | force: overwrite the remote branch, commits of others included |
| --tags | push tags as well, which push does not do on its own |
| --delete <branch> | delete the branch on the server |
| --all | push every local branch |
| -n | dry run |
示例
git push -u origin feature/loginpublishes the branch and remembers the pairing
git push --force-with-leasethe safe force, used after a rebase
git push origin --delete old-featureremoves the branch on the server
难的地方在于撤销有好几种:把分支的指向挪走,和补一个反向提交,不是一回事。
怎么看
- 方括号 [ ] 表示这部分可以不写。
- 省略号 … 表示可以写多个。
- 选项区分大小写——有些命令里 -r 和 -R 不是一回事。
常见问题
Q. git push 是做什么的?
把你的提交推到远端;--force 会覆盖远端分支,连别人推的提交都可能被抹掉,所以用 --force-with-lease,远端一动它就拒绝。
Q. 怎么写?
git push [-u] [--force-with-lease] <remote> <branch> —— 方括号表示可以省略的部分。
Q. 值得记的选项有几个?
这里列了 7 个,完整列表在 man git。这条命令属于git。
相关命令
man 手册: man git-push