简体   繁体   English

如何从git merge中排除特定的提交(永远)

[英]How to exclude a particular commit from git merge (forever)

I'm developing some web application (php, codeigniter). 我正在开发一些Web应用程序(php,codeigniter)。 Today a time to push it to github has come, but I've encountered an issue I can't manage. 今天是时候把它推向github了,但我遇到了一个我无法管理的问题。

I've got 2 branches: 我有两个分支:

  • master - this branch should be used for github pushing, does not contain credentials or any other sensitive data (just public code) master - 此分支应该用于github推送,不包含凭据或任何其他敏感数据(只是公共代码)
  • dev - this is master's child, used for development, does contain credentials (of my private app instantion) dev - 这是master的孩子,用于开发,确实包含凭据(我的私人app instantion)

By credentials I mean: database login, password, host, user; 凭证我的意思是:数据库登录,密码,主机,用户; oauth services id / secrets; oauth服务id / secrets; encryption_key. encryption_key。 Credentials are stored in 2 separated files within /application/config folder. 凭据存储在/ application / config文件夹中的2个单独文件中。

The idea is that I'll make all changes on dev, than merge dev into master, and pull master content to github (but master can't contain my private credentials). 我的想法是,我将在dev上进行所有更改,而不是将dev合并到master中,并将master内容拉到github(但master不能包含我的私有凭据)。

This is what I've done till now: 这就是我到目前为止所做的事情:

  1. Removed all credentials from /application/config/config.php and /applications/config/database.php (as I don't want them to be public on github) they've become an empty strings like: $db['default']['hostname'] = ''; 从/application/config/config.php和/applications/config/database.php中删除了所有凭据(因为我不希望它们在github上公开)它们变成了一个空字符串,如:$ db ['default' ] ['hostname'] ='';
  2. Started git repository and made an initial commit - the default branch that was created is named 'master' 启动git存储库并进行初始提交 - 创建的默认分支名为“master”
  3. Pulled master into github 拉大师到github

And it's pretty cool till now - I've got my project code on github with no credentials within. 到现在为止它非常酷 - 我的github上的项目代码没有凭据。 Next I need to make some changes in my project, so I: 接下来我需要对我的项目进行一些更改,所以我:

  1. Created new branch 'dev' 创建了新的分支'dev'
  2. Stored my credentials into dev, and make a commit - I need dev instantion to have credentials as I'm uploading this to ftp server every time I change something in the code (I don't use local LAMP or anything like this in this project) 将我的凭据存储到dev中,然后进行提交 - 我需要dev instantion才能拥有凭据,因为每次我在代码中更改某些内容时都会将其上传到ftp服务器(我在本项目中不使用本地LAMP或类似的东西) )

So now I need to make some change in dev, upload it and pull to github so I: 所以现在我需要在dev中进行一些更改,上传它并拉到github所以我:

  1. Make an change on dev (let's say add new feature) 对dev进行更改(假设添加新功能)
  2. Checkout to master 结帐以掌握
  3. Merge dev into master. 将dev合并为master。

What I expected to happen: Git will ask me which version of configs should be used in 'master' as it is different in both branches. 我期望发生的事情: Git会问我在'master'中应该使用哪个版本的配置,因为它在两个分支中都是不同的。 I will use diff to chose a 'master' verion of files (which does not contain credentials). 我将使用diff来选择文件的“主”版本(不包含凭证)。 Git will remember my choice, and in the future I will not have to chose again when I'll merge dev into master. Git会记住我的选择,将来我不会再选择当我将dev合并到master中时。 Git works like this on one of my other projects, where dev is a master branch and instantions are it's children (In this case dev is a child and I merge child into parent). Git在我的其他项目中就是这样的,其中dev是一个主分支,而instantions是它的子代(在这种情况下,dev是一个孩子,我将child合并为parent)。

What happened: Git just copied credentials from dev to master, did not ask me about that. 发生了什么: Git只是将凭证从dev复制到master,没有问我这个问题。 So now my master branch is 'tainted' by credentials and I can't push it to github anymore. 所以现在我的主分支被凭证“污染”,我不能再把它推到github了。

My questions are: 我的问题是:

  1. Why is that happening, how can I avoid this? 为什么会这样,我怎么能避免这种情况?
  2. Is there any other (better?) way to handle that kind of issue. 有没有其他(更好?)方式来处理这类问题。

Please let me know if anything is unclear, any help will be appreciated. 如果有任何不清楚的地方,请告诉我,任何帮助将不胜感激。

Git will only flag a conflict if files in your master branch were changed after your original branch to dev, then the same files were changed in dev. 如果主分支中的文件在原始分支后更改为dev,则Git将仅标记冲突,然后在dev中更改相同的文件。

I suggest you add a .gitignore entry for your credentials, or separate them using an ENVIRONMENT variable, in codeigniter this is very easy, all you have to do is on your apache config (vhost if your using them) is add SetEnv APPLICATION_ENV development then you can add a folder inside application/configs called development , now when you are running in development environment, these configs will take precedence over the ones in the base config directory. 我建议你为你的凭证添加一个.gitignore条目,或者使用ENVIRONMENT变量将它们分开,在codeigniter中这很容易,你所要做的只是你的apache配置(vhost,如果你使用它们)是添加SetEnv APPLICATION_ENV development然后你可以在application/configs添加一个名为development的文件夹,现在当你在开发环境中运行时,这些配置将优先于基本配置目录中的配置。

This isn't so much about gitignoring files, or removing commits, but a good file structure, and environment setup to differentiate between the separate environments, you an use development , staging , and production (which is the default) 这不是关于gitignoring文件,删除提交,而是良好的文件结构和环境设置,以区分不同的环境,使用developmentstagingproduction (这是默认设置)

otherwise add a .gitignore row to tell git to ignore those certain files. 否则添加.gitignore行告诉git忽略那些特定文件。

Git ingore will help. Git ingore会有所帮助。 Read this blog post for solution. 阅读此博客文章了解解决方案。

http://blog.pagebakers.nl/2009/01/29/git-ignoring-changes-in-tracked-files/ http://blog.pagebakers.nl/2009/01/29/git-ignoring-changes-in-tracked-files/

You can include the credentials from a configuration file and add that file to .gitignore . 您可以包含配置文件中的凭据,并将该文件添加到.gitignore

The config file can consist of settings for the dev, preproduction and production environments. 配置文件可以包含开发,预生产和生产环境的设置。

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

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