0

I have a website I'm working on that contains the "master" branch, which is exactly what is on the server, and a branch called "development", where I code new features before merging it into master.

The problem is that I have a file that should be different in both versions (.htaccess). Is there a way to merge everything from "development" to "master", except .htaccess?

  • You can [Cherry-pick](http://stackoverflow.com/questions/449541/how-do-you-merge-selective-files-with-git-merge) it. – Brandon Jun 20 '14 at 19:27
  • 1
    Take a look at: http://stackoverflow.com/questions/449541/how-do-you-merge-selective-files-with-git-merge – pooopies Jun 20 '14 at 19:28

2 Answers2

0

I'd add .htaccess to your .gitignore file. It might make deploying a bit more difficult, but it'll be much better than cherry picking it out every time.

Keep in mind you'll need to remove .htaccess from the index (git rm --cached) in order for this to take effect.

SomeKittens
  • 38,868
  • 19
  • 114
  • 143
  • 1
    This is the correct way to do this, but there's a step you left out. Adding .htaccess to your .gitignore file means git will not track changes to this file. That means if you need it to change as part of your deploy or merge you will need a script that alters it on that event. If it needs to be different based on the branch itself, look into git hooks. If it needs to be different once you deploy it to an environment, there are other options at your disposal. Perhaps leaving it the correct value on the destination environment. – Brian Mego Jun 20 '14 at 19:31
  • 2
    @BrianMego My approach would probably be to have a `development.htaccess` file, and a `production.htaccess` file, and copy or symlink `.htaccess` to `production.htaccess` as part of the build/deploy. – Ajedi32 Jun 20 '14 at 19:38
0

The unintended problem with most merge processes that you will run into at this point is that your .htaccess is already part of the development history, i.e. even if you remove now, and then merge the history of your .htaccess will exist in the history of master.

If this is a one-time merge, I would squash your development into master and remove the .htaccess at that time, i.e.:

git merge --squash development

This will stage every file that that is different in your development branch to be committed as a single commit onto master. Now you can remove .htaccess

git reset .htaccess
git checkout .htaccess

The first line will unstage your changes, the second will remove the modifications. Now you can commit your changes

Arne Claassen
  • 14,088
  • 5
  • 67
  • 106