开发者

Merging in git: via git-svn, says Already Up-to-date, but git-diff says there are differences

I'm using git-svn to work with a codebase and I need to merge changes in trunk to my branch.

I have both branches fetched in git, and when I run git diff trunk while开发者_开发问答 in my branch, I can see all the changes.

When I run git merge heads/trunk, however, I get a message "Already up-to-date".

It's clearly not up to date. What am I doing wrong?


Nothing like an example. Here's how to get into this situation:

(starting in an empty directory):

> git init
> echo "hello" > a.txt
> git add -A
> git commit -m "Created a on master"
> git branch test
> git checkout test

At this point a.txt are identical on master and test branches

> echo "goodbye" > a.txt
> git add -u
> git commit -m "Changed a on test"

Now (obviously) there will be differences:

> git diff --name-status master 

M       a.txt

yet git has nothing to merge:

> git merge master
Already up-to-date.

That's because the changes are made here on test, not on master. If you switch to test, diff will report similarly, but merge will now merge in the changes from test to master:

> git checkout master
> git diff --name-status test 

M       a.txt
> git merge test
Updating 088cd9d..3d8c8e2
Fast-forward
 a.txt |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Git merging is directional, merging from branch A to B is not the same as merging from B to A.


"Already up-to-date" can mean:

  • trunk is a parent of master (all the changes from trunk have already been merged to master)
  • or you are working on a detached head (which can happen if you checkout directly a SHA1 commit reference, or a tag).

Note: be aware of git svn caveats

Merge tracking in Subversion is lacking and doing branched development with Subversion can be cumbersome as a result.
While git svn can track copy history (including branches and tags) for repositories adopting a standard layout, it cannot yet represent merge history that happened inside git back upstream to SVN users.
Therefore it is advised that users keep history as linear as possible inside git to ease compatibility with SVN

For the sake of simplicity and interoperating with a less-capable system (SVN), it is recommended that all git svn users clone, fetch and dcommit directly from the SVN server, and avoid all git clone/pull/merge/push operations between git repositories and branches.
The recommended method of exchanging code between git branches and users is git format-patch and git am, or just 'dcommit'ing to the SVN repository.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜