9

I need to exclude the dist/ folder from merging errors, I don't care if it is theirs, ours or other strategy but I need to keep it in the revision control since this is the way to deploy to Heroku. .gitattributes script seems to be the way to go. But I can't seem to make this work.

I read this canonical answer and this similiar answer but can't find out what I'm doing wrong.

My .gitattributes config:

* text=auto
dist/ merge=keepMine

The relevant part of my .git/config :

[merge "keepMine"]
    name = always keep mine dist during merge
    driver = keepMine.sh %O %A %B

and keepMine.sh (in my project root folder, no the folder isn't in the path, but copying to a folder in the path didn't help and isn't a good solution since the script should be part of revision control so all developers would get it):

# copied as is from the SO answer
# I want to keep MY version when there is a conflict
# Nothing to do: %A (the second parameter) already contains my version
# Just indicate the merge has been successfully "resolved" with the exit status
exit 0

EDIT: Also tried git config merge.keepMine.driver true as suggested in one of the SO answers above. Didn't work.

But I'm still getting merge errors (If I create them) for example in dist/styles/sdkasl.main.css for example.

What am I doing wrong? Thanks for the help.

Community
  • 1
  • 1
alonisser
  • 11,542
  • 21
  • 85
  • 139
  • I'm at best a git novice, but I've been following this question for the past few days hoping to see a solution to your issue. Did you get it resolved? If not, perhaps [How to make git ignore a directory while merging](http://stackoverflow.com/questions/14369378/how-to-make-git-ignore-a-directory-while-merging) can help? –  Jan 24 '14 at 23:52
  • @ChronoKitsune this is another issue, I don't want to do a manual merge (in which that answer would help) but an automated merge.. – alonisser Jan 25 '14 at 18:31
  • I just tried what you described and it works for me. Could you please update your question with the output from a failing merge? E.g. GIT_TRACE=2 git merge ... – Lasse Feb 24 '14 at 13:10
  • 1
    Please post the output of `git check-attr --all dist/styles/sdkasl.main.css` – jthill Apr 30 '14 at 07:17
  • That's an oldy question, not sure I even have those files anymore.. I'll check. just for the sake of learning – alonisser Apr 30 '14 at 07:52
  • you don't you keep this directory as a git [submodule](http://git-scm.com/docs/git-submodule)? what you are trying to do cause alot of history issues in git in case you need to check diffs or revert some commits in the future. – Anas Al Hamdan Mar 30 '15 at 11:06
  • 1
    Shouldn't this be `dist/**` in the *.gitattributes* file? – kfunk Jan 07 '16 at 02:01
  • `.gitattributes` patterns follow the same convention as `.gitignore` so a folder would include everything in that folder and below. – Haralan Dobrev Jan 26 '18 at 18:18

1 Answers1

0

The documentation isn't great in this one.

You can also use Git attributes to tell Git to use different merge strategies for specific files in your project.

Sounds great! We can read about merge strategies here and there's one called ours that'd be really helpful.

Unfortunately the next line crushes that dream. Emphasis mine.

One very useful option is to tell Git to not try to merge specific files when they have conflicts, but rather to use your side of the merge over someone else’s.

Sadly for us, if the changes to dist/ in feature don't conflict with master then they'll be merged into dist/ on master. The second answer to the question you linked above discusses this.

I'd suggest a post merge hook that resets dist/ to some pristine state.

Adam
  • 4,180
  • 2
  • 27
  • 31