简体   繁体   中英

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 ". 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. 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.

I'm going to suggest @Lasse's comment as an answer:

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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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