Re: Dangers of working on a tracking branch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 16 Feb 2007, Bill Lear wrote:

> Ok, I'm trying to come up with an experiment that verifies this, so
> I can give a concrete example to our developers.
> 
> I don't seem to be able to get it to fail, but I sure remember having
> severe problems with this in practice.

Try this:

	# create first repository
	mkdir foo
	cd foo
	git init-db
	echo FOO > biz
	git add biz
	git commit -a -m "commit 1 in foo"

	# clone this repository elsewhere
	cd ..
	git clone foo bar
	cd bar

	# modify the tracking branch (origin in this case)
	git checkout origin
	echo BAR > biz
	git commit -a -m "modify tracking branch in bar"

	# go back to original repo and modify it
	cd ../foo
	echo BAZ > biz
	git commit -a -m "modify master branch in foo"

	# now back to the cloned repo
	cd ../bar
	git fetch	# it fails
	git push	# itfails
	git pull	# it almost performs the merge but...

Because you now have a conflict to resolve, you might wish to inspect 
what the remote state actually is.  But because you modified your origin 
branch you don't have any pristine version of what the remote has, 
except maybe the MERGE_HEAD.  But if you work in a complex project, 
MERGE_HEAD will not stay there for long if you move around.

Imagine that you want to move to another branch, say master, because 
right now you don't feel like resolving this ultra complex merge:

	git checkout master	# it fails (unresolved merge)
	git checkout -f		# succeeds, discarding the merge

But at this point you still don't have any way to look at the remote's 
content.  If instead the origin branch was untouched and the work had 
occurred in the master branch, then you could git-log the origin branch, 
you could git-diff your master branch with the origin branch, you could 
even checkout the origin content to test it, etc.  But since you added 
commits on top of the origin branch then you cannot do any of that 
because it is impossible to update the origin branch with the remote 
stuff.  Well you can force it of course:

	git fetch -f

But by doing so you lose all the work you committed on top of origin.

BTW I checked out v1.4.4.1 to verify the above operations..... and this 
GIT version really feels odd compared to v1.5.0


Nicolas
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]