简体   繁体   English

如何允许某些git提交到分支但阻止它们合并到master中?

[英]How do I allow certain git commits to a branch but prevent them being merged into master?

Sometimes I branch out to write a feature but need an initial local commit which tweaks certain files in a way for me to work locally. 有时,我会扩展功能来编写功能,但是需要初始的本地提交,从而以某种方式对某些文件进行调整以使我可以在本地工作。 These changes are not to be merged back into master, so when the branch is ready I rebase it and remove the initial commit, which typically starts with the log message " DONT MERGE ". 这些更改不会被合并回master,因此当分支准备就绪时,我将其重新设置基础并删除初始提交,该提交通常以日志消息“ DONT MERGE ”开头。 But from time to time I still manage to merge that into master. 但是我仍然时不时地将其合并为大师。

Looking through the git hooks folder I see pre/post commit hooks, but nothing seems to look ideal for merges. 通过git hooks文件夹查看,我看到了提交前/提交后的钩子,但是似乎没有什么是合并的理想选择。 Is any of those hooks able to look at commits before them being merged too? 这些钩子中的任何一个也能够在合并之前查看提交吗? I want this to work locally on my machine, so I'm not looking for solutions which involve pushing to an external server like GitHub or Bitbucket. 我希望它可以在我的机器上本地运行,所以我不希望找到涉及推送到GitHub或Bitbucket等外部服务器的解决方案。

I'm going to suggest @Lasse's comment as an answer: 我将建议@Lasse的评论作为答案:

It sounds like you want to have different configurations for local and production development, in that case you should look into having a config file that is ignored by git that you change locally. 听起来您想为本地和生产开发使用不同的配置,在这种情况下,您应该考虑使用一个在本地更改的git忽略的配置文件。 You could commit different example config files that are not actually used so that you don't have to remember all the details. 您可以提交未实际使用的其他示例配置文件,从而不必记住所有详细信息。 For example: 例如:

config.txt
configProductionExample.txt
configLocalDevExample.txt

Or you could commit multiple startup scripts, one for each environment you want to work in. For example: 或者,您可以提交多个启动脚本,每个启动脚本用于您要使用的每种环境。例如:

startProduction.sh
startLocalDev.sh

暂无
暂无

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

相关问题 我在git的错误分支上创建了一个分支,并将旧分支合并到master中,如何从另一个分支中删除提交? - I created a branch off of the wrong branch in git and already merged the old branch into master, how do I remove the commits from the other branch? 如何获取所有 git 提交到合并分支的列表? - How do I get a list of all git commits to a merged branch? 使用 Git,在我的代码提交合并到 master 分支后,我是否要删除我的远程分支,再次克隆 master 并检查下一个分支? - With Git, after my code commits are merged to the master branch, do I delete my remote branch, clone master again and checkout the next branch? 如何锁定分支与母版合并? - How do I lock a branch from being merged with master? Git南瓜在与master合并的分支中提交 - Git squash commits in a branch merged with master 如何允许git merge commit to master但阻止非合并提交? - How can I allow git merge commits to master but prevent non-merge commits? 如何防止特定分支在git中合并? - How to prevent a specific branch from being merged in git? 合并后,合并分支的提交会成为主分支的一部分吗? - Do commits of a merged branch become part of master branch after merge? Git:如何防止特定提交合并到另一个分支? - Git: How can I prevent a specific commit from being merged into another branch? Git:如何列出合并分支上的提交? - Git: How to list commits on a merged branch?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM