2

I have a git repo on github.

Someone has taken the repo (copied, not forked; I'm not entirely sure how or why), done a lot of work on about a quarter of the files therein, and then uploaded a new git repo to their own area in github containing exactly one commit - an initial commit, containing everything.

If I try to git merge, then every single file is coming up as a conflict; it thinks we've both added the files from scratch. Which of course we have.

I could manually diff and merge them all. But I'd really rather not have to.

I've added in his repo as a remote.

Is there an obvious way to merge in only the files which have been changed?

piersb
  • 609
  • 9
  • 22

2 Answers2

0

Possible solution:

git fetch https://github.com/blah/other-repo.git <branch> && git cherry-pick <commit>

It behaves like a merge, if conflicts appear you will have to resolve them manually but only from the modified files.

andybeli
  • 836
  • 7
  • 14
  • There is only one commit in the other repo, which contains everything; so a git cherry-pick is, in this circumstance, identical to a git merge. – piersb Apr 16 '15 at 17:11
0

Right, it looks like the file permissions everywhere in the new commit had changed to 755; that's what was causing everything to be flagged as changed.

How do I make Git ignore file mode (chmod) changes? suggests that the problem is solvable by using

git config core.fileMode false

Unfortunately, this didn't work for me; possibly because it only looks at changes in the working tree rather than in commits.

Instead, I went into the new branch and did the following

git diff --summary master | grep  'mode change 100644 => 100755' | cut -d' ' -f7- | xargs -I {} chmod -x {}

Which then turned off all of the executable bits in the new branch.

git commit -a
git log --oneline

2f80315 Changing permissions to match master...
c7896aa The Commit From The Other Fella

git checkout master
git cherry-pick 2f80315
git commit --allow-empty

Makes sure that all of the permissions on every file that wasn't edited match, and at this point a

git diff newfellasbranch

shows me the changes that they've made. I'm happy, so

git merge newfellasbranch --strategy-option theirs

There may well be a simpler way of doing this.

Community
  • 1
  • 1
piersb
  • 609
  • 9
  • 22