在使用 git push 命令推送代码到服务器时,不一样的需求会有不一样的用法。具体说明一些使用实例以下。git
当咱们使用 git reset 命令回退本地 git log 显示的 commit 信息后,使用 git push
提交改动到远端服务器会报错,打印相似下面的错误信息:服务器
提示:更新被拒绝,由于您当前分支的最新提交落后于其对应的远程分支。code
此时,若是想强制用本地 git log 的 commit 信息覆盖服务器的 git log,能够使用 git push -f
命令来推送代码到服务器。查看 man git-push 对 -f 选项说明以下:rem
-f, --force
Usually, the command refuses to update a remote ref that is not an ancestor of the local ref used to overwrite it.
This flag disables these checks, and can cause the remote repository to lose commits; use it with care.it
即,-f 选项能够用本地的 git log 信息强制覆盖服务器的 git log 信息。因为这会致使部分提交log信息丢失,请当心使用,确认这样作的必要性。class
在 git 中,能够使用下面两个命令来删除远端服务器上的分支。sed
在 git push origin :<branchName>
命令中,冒号 ":" 前面的参数是要推送的本地分支名,这里没有提供,至关于推送一个本地空分支。冒号 ":" 后面的参数是要推送到服务器的远端分支名。date
这个命令推送一个空分支到远端分支,至关于远端分支被置为空,从而删除 branchName 指定的远端分支。command
git push origin --delete <branchName>
命令本质上跟 git push origin :<branchName>
是同样的。查看 man git-push 对 --delete 选项说明以下:推送
-d --delete
All listed refs are deleted from the remote repository. This is the same as prefixing all refs with a colon.
即,--delete
选项至关于推送本地空分支到远端分支。