1

I'm trying a

git rebase --onto master myremote/master~21 myremote/master

to add the latest 21 commits from a remote repository on mine.

What git tells me is that there's a conflict — but how's that possible?

In my understanding it's just taking that 21 commits and applying them on top of my master. How can there be conflicts?

Thanks for help!

I'm doing that btw because somehow I messed up my git-svn repository (the remote), and there's 21 commits which I don't manage to commit to subversion. So I'm trying with a fresh git-svn clone, in which I'm adding those 21 commits.

Andy
  • 4,783
  • 2
  • 26
  • 51

1 Answers1

0

There is conflict if:

  • master has commit that are not in myremote/master.
  • those commits include common files/changes with one the last 21 myremote/master commits.

If somehow the fresh git-svn clone has different SHA1 than the previous git-svn repo, then there is no close common ancestors, and the chances of conflicts are that much higher.
See "How to identify conflicting commits by hash during git rebase?" for illustrations of conflicts during a rebase.


One way to reset your local master to myremote/master would be to:

git checkout -b tmp myremote/master  # local tmp branch from myremote/master HEAD.
git merge -s ours master             # ignore completely master content
git checkout master
git merge tmp                        # fast-forward to tmp HEAD

If you hadn't made any changes in your local master before fetching myremote/master, this should work.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I don't understand. Why would any commits in master matter? A rebase is just resetting the current branch (here myremote/master) to (here master). So everything should just be applied on top of master, right? – Andy Feb 08 '11 at 12:10
  • In other words: Isn't there a way to simply apply those 21 commits without having git check for common ancestors and crap? – Andy Feb 08 '11 at 12:15
  • @Andy: for conflicts during a rebase, see http://stackoverflow.com/questions/2118364/how-to-identify-conflicting-commits-by-hash-during-git-rebase. The question in your case is: is the SHA1 for `master/HEAD` (before any rebase) the same than `myremote/master~22`? If not, the common ancestor is further down the history of `master`, hence all those conflicts. – VonC Feb 08 '11 at 12:29
  • Thanks for that answer. But as I understand the documentation on git rebase, it's NOT CHECKING FOR COMMON ANCESTORS on the . At least that's what I want to do and I thought that rebase --onto would do that. – Andy Feb 08 '11 at 12:35
  • @Andy: I have completed my answer with a possible way to reset your master, taken after the ours merge strategy presented in http://stackoverflow.com/questions/4911794/git-command-for-making-one-branch-like-another/4912267#4912267 – VonC Feb 08 '11 at 12:36
  • Thanks. I saw that actually the SHA1 of the common commits are different in myremote/master and master. So by doing the merge between tmp and master I'll kind of get a problem because of that, right? And I still don't understand why the master matters in the mentioned rebase. – Andy Feb 08 '11 at 12:59
  • @Andy: I believe that different SHA1 are a possible cause for those conflicts. Did you try the merge I mention instead of a rebase? Note that would reset the all `master` branch, which might not be compatible with a `svn dcommit` in your `git-svn` repo, so it is probably not the right solution for you since you confirm the SHA1 for *common* commits don't match. – VonC Feb 08 '11 at 13:07
  • I tried the first steps, but didn't finish when I realized that all that commits would be in there double. – Andy Feb 08 '11 at 13:54
  • I now also understand that git rebase will do a git reset master on the myremote/master branch. But I don't know what the result will be, since the last commit in master is not in myremote/master – Andy Feb 08 '11 at 15:04
  • Hi thanks for asking. I'm still working on it. But the question I asked here was answered. (= I'm trying an approach with patches now — but I always get the message "patch doesn not apply" and I don't understand why. – Andy Feb 09 '11 at 15:53
  • @Andy: ok, interesting. That could be a question of its own, that "patch does not apply" ;) (I have no answer right now but I hope other Git specialists have some clues on that issue) – VonC Feb 09 '11 at 16:31