Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore files in Git merge?

I'm working on a (Django) website with two branches: master and dev.

master is the production version and no work should be done here directly. All the changes should come from merging dev branch, once it is considered to be stable.

dev, as you may guess, is the development branch and all the changes are made here (and subbranches).

In the server I have two websites working, the production one (uses master branch) and another private for development, with dev subdomain that uses dev branch.

The problem is that all the configuration files, static files (images, etc.) are inside the control version to be able to easily push them to the server. But, if these kind of files (static, config...) are modified in dev to just debug in the server and then I need to merge with master... How can I set some files and dirs to be ignored when merging dev into master?

I've been searching and I've found some related questions, but they tell you to use .gitattributes with merge=ours. However, this approach has a big caveat: it only applies the strategy if the file is modified in the two branches, but this isn't my case.

Any tips on how should I go on?

like image 672
Caumons Avatar asked Sep 28 '13 16:09

Caumons


People also ask

How do I ignore a merge in Git?

The simplest way, if you have unmerged paths, use git merge --abort to abort the merge. This way your code will look the same as it was before trying to merge with some other branch...

How do I make Git ignore a folder while merging?

Let's say I'm on branch staging want to merge dev and ignore changes in /build folder: git checkout staging # go to staging branch git checkout dev .

How do I ignore files in Git?

If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a .gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.


2 Answers


git checkout master

git merge --no-log --no-ff --no-commit dev

git checkout master &ltfiles-you-don't-want-to-merge&gt


git add &ltfiles-you-don't-want-to-merge&gt

git commit -a

~~~ Test / Build ~~~

git push origin master 


like image 59
forvaidya Avatar answered Oct 14 '22 12:10

forvaidya


To be honest, git sounds like the wrong place to be solving this problem.

Django offers facilities for having separate settings/configuration for production and development environments. I suggest you take a look at this post: Django: How to manage development and production settings?

If you follow the advice in the post above, you can muck with the configuration, etc. for your dev environment and then merging to master will be harmless as production will have its own configuration.

like image 27
ksimons Avatar answered Oct 14 '22 12:10

ksimons