确认git推送命令
如何在具体分支中配置 git Push 命令的一些确认?我有生产分支,有时我忘记了我在生产分支中并且不推送这些更改。
How I can configure some confirmation on git push command in concrete branch? I have production branch and sometimes I forgot that I in production branch and push not those changes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一种可能的解决方案是删除与“生产”分支关联的配置。
这样,您必须提及您想要从哪个遥控器拉出(或推送到哪个遥控器)。
如果您为拉取定义了一个别名,其中:
您确信您将无法在不输入其他参数的情况下对该分支执行简单的“git pull”。
One potential solution would be to remove the config associated with 'production' branch.
That way, you have to mention to what remote you want to pull from (or push to, for that matter).
If you define an alias for the pull which:
you are sure you will not be able, for that branch, to do a simple "git pull" without entering additional parameters.
您所需要的只是用于提交到受保护分支(例如“master”)的预推送挂钩。
Git 为各种操作提供了许多钩子(如文档)。钩子是带有特殊输入的 shell 脚本,由 git 在特定时间调用,因此您可以根据需要调整它们,但是要在推送到 master 之前要求确认,您可以这样做:
请注意,当要求用户输入时,您必须给出它一个要读取的终端,如问题 如何要求用户输入Git 挂钩?。
PS:需要 GIT 版本 1.8.2 或更高版本才能使用钩子。
All you need is the pre-push hook for the commits into protected branches like "master".
Git offers a number of hooks for various actions (as written in the documention). The hooks are shell scripts with special inputs called at specific times by git so you can adapt them as you want, but to ask a confirmation before pushing to master you can do this:
Note that when asking for user input, you have to give it a terminal to read from, as explained in the question How to ask for user input in a Git hook?.
PS: GIT Version 1.8.2 or above needed for hooks to be available.
您可以
git fetch
,然后git status
会告诉您是否已推送新提交。You can
git fetch
, thengit status
will tell you if new commits have been pushed.