简体   繁体   English

如何防止git从当前分支中拉出来

[英]How to prevent pulling in git from different than the current branch

Currently if you are in branch V2 and you do "git pull origin V3" it merges V3 to V2 and doesn't even warn or prompt about it. 目前,如果你在分支V2并且你做“git pull origin V3”它将V3合并到V2,甚至没有警告或提示它。 Can this option somehow be blocked? 这个选项可以以某种方式被阻止吗? I read all the similar questions here and people suggest I can use fetch or show a warning in this case. 我在这里阅读了所有类似的问题,人们建议我可以使用fetch或在这种情况下显示警告。 This is OK, I will start using fetch instead of pull but I want to block other pull users. 这没关系,我将开始使用fetch而不是pull但我想阻止其他pull用户。 Also, I assume there are cases when you have to make pull instead of fetch. 此外,我假设有些情况下你必须做拉而不是取。 Thanks 谢谢

If you link the remote branch as the local branch upstream source, you won't need to manually write the remote and branch. 如果将远程分支链接为本地分支上游源,则无需手动编写远程和分支。

# set upstream
git push -u origin V2

# Then simply pull from default branch
git pull

This'll work. 这个都行。 Though, you're mostly always better to fetch and rebase your local branch on top of the remote. 虽然,你在这里几乎都始终是更好的fetchrebase在远程的顶部当地分行。 This make a cleaner and more usable history. 这使得历史更清晰,更实用。

To answer the question directly though, you could create a custom before merge hook which check the branches being merged and alert when you're merging a remote branch not matching the local branch name. 要直接回答这个问题,您可以在合并挂钩之前创建自定义,检查要合并的分支,并在合并与本地分支名称不匹配的远程分支时发出警报。 But, this is overhead and might be annoying as it'll check on every merge (because git pull === git fetch && get merge ) 但是,这是开销,可能会很烦人,因为它会检查每个合并(因为git pull === git fetch && get merge

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM