1

I have a common file "foobar" across master and its customer private branches. Previously they diverged and now I've managed to get a single file that apples to all private branches in master.

In order for my customer branches to track master, I've successfully used git rebase -i master.

However, I've now forcefully "synced" the git checkout master -- foobar in my private branch, committed it and now my git rebases are erroring out. Fixing by hand each time takes far too long.

git checkout master -- foobar && git add foobar && git rebase --continue

Can someone offer a tip or two how to get out of this sticky situation? Reverting my commit on the private branch is not a problem. Basically I want all my branches to use the foobar file from master, end of.

hendry
  • 9,725
  • 18
  • 81
  • 139
  • Can they use the rest of `master`, too, or just that one file? – Christopher Jul 09 '12 at 17:41
  • Just that one file in this case. The private branch is divergent in many files. I rebase them against master as it's essentially authorative, but config files etc. etc. differ. – hendry Jul 09 '12 at 17:55
  • There are a variety of solutions here, but none of them look any easier / less messy: http://stackoverflow.com/questions/449541/how-do-you-merge-selective-files-with-git-merge. – Christopher Jul 09 '12 at 18:24

2 Answers2

0

Use a custom merge driver through attributes:

git checkout master
echo foobar merge=checkoutMaster > dir/to/foobar/.gitattributes
git add dir/to/foobar/.gitattributes
git commit -m "Always use master version of foobar"
git config merge.checkoutMaster.name "Use master version of foobar"
git config merge.checkoutMaster.driver "~/checkoutMasterFoobar.sh %O %A %B"
echo "git checkout master -- dir/to/foobar/foobar && exit 0" > ~/checkoutMasterFoobar.sh
Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
  • Why the driver? Why is this so complicated!? I just want my rebases to work like they once did... yikes. – hendry Jul 10 '12 at 07:24
  • The issue is that you want one file to be treated differently than all the others. It's a very specific thing you want to make work here. I usually don't track a config file like that or purposely make invalid entries with in it and have search replace scripts work on it prior to deploy. – Adam Dymitruk Jul 10 '12 at 08:17
  • Ok, let me re-phrase my question in the sense I want to just have a "one off" sync at this time and make my rebases not bomb out. – hendry Jul 10 '12 at 10:00
  • You have no choice as rebasing tries to apply all commits in your branch against a new base version of your file. Consider changing your workflow to use merges instead of rebasing all the time. It can appear scary when you rely on a graphical view of history, but that wears off with time as you get used to the set manipulation of `git log` arguments. – Adam Dymitruk Jul 10 '12 at 17:22
  • My fear with git merge is that it is more likely to trump values in my private branch. – hendry Jul 10 '12 at 18:23
  • Why would merge do that? Even for your specific custom behaviour, you know that a driver will only execute once. With rebases, it will execute for each commit. – Adam Dymitruk Jul 10 '12 at 19:20
0

I think I've found the solution whereby I've rebased and then checkout out the change from master.

Bad things happen when you do the reverse. I.e. checkout the file from master, then rebase.

hendry
  • 9,725
  • 18
  • 81
  • 139