Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make git ignore a directory while merging

Tags:

git

merge

As interesting and useful as the answer to How to setup a git driver to ignore a folder on merge was, it did not answer the original question which still has me stumped.

Unlike the question linked to above, I have two branches with the same set of directories and for merging one into the other I need git to ignore one directory completely.

I tried it with my own merge driver as described in How do I tell git to always select my local version for conflicted merges on a specific file? but the problem with this approach is that this driver is only invoked when there is an actual conflicting file in these two branches. Whenever the changes of a file are only on one branch, git merges them without calling my merge driver.

This leads to changes in files in the directory that I do not want. Any idea how I could make git ignore each and every file in that directory all the time - whether it was touched or not?

like image 917
Sebastian Thiebes Avatar asked Jan 16 '13 22:01

Sebastian Thiebes


People also ask

How do I ignore a folder in git bash?

gitignore" file in the folder with "*" as the content. This file will make Git ignore all content from the repository. But . gitignore will be included in your repository.

How do you stop a git process from merging?

On the command line, a simple "git merge --abort" will do this for you. In case you've made a mistake while resolving a conflict and realize this only after completing the merge, you can still easily undo it: just roll back to the commit before the merge happened with "git reset --hard " and start over again.

How do I merge without committing?

OPTIONS. Perform the merge and commit the result. This option can be used to override --no-commit. With --no-commit perform the merge and stop just before creating a merge commit, to give the user a chance to inspect and further tweak the merge result before committing.


1 Answers

I don't actually use Git, but I think this would work for your case:

Use something like what's specified here: https://gist.github.com/564416

git checkout master     git merge --no-commit --no-ff development git reset -- /path/to/folder # revert updates from path git commit 

Again, I don't use git, I am just deferring to how I think things work based on my experience with TryGit.

  1. checkout master
  2. merge, but don't commit, no fast forward.
  3. merges are now staged, so reset that entire directory tree
  4. commit
like image 110
user606723 Avatar answered Sep 21 '22 13:09

user606723