Thread (3 messages) flat view 3 messages, 3 authors, 2016-06-15

checkout to other directory (Re: [PATCH 3/3] setup: always honor GIT_WORK_TREE and core.worktree)

From: Jonathan Nieder <hidden>
Date: 2016-06-15 22:50:26

Maaartin wrote:
Actually I did mostly something like

git --work-tree /tmp/somewhere checkout somebranch -- .
  && winmerge . /tmp/somewhere

at root of my normal work tree as a poor man's replacement for

git difftool somebranch

This is probably no good idea as it mixes up the index.
Right.  I think the simplest (and usual) method is something like

	rm -fr /tmp/somewhere &&
	mkdir -p /tmp/somewhere &&
	git archive somebranch | (cd /tmp/somewhere && tar -xf -)

But suppose that the tracked tree is very big, so that re-creating
/tmp/somewhere each time is expensive.  Then you can do

	(
		GIT_DIR=$(pwd)/.git &&
		GIT_INDEX_FILE=$(pwd)/.git/somewhere-index &&
		export GIT_DIR GIT_INDEX_FILE &&

		cd /tmp/somewhere &&
		git update-index --refresh -q &&
		git read-tree --reset -m -u somebranch
	)

The state of /tmp/somewhere is remembered in the somewhere-index file.

In practice, I tend to use something closer to the following:

	sh /usr/share/doc/git/contrib/git-new-workdir repo /tmp/somewhere &&
	(
		cd /tmp/somewhere &&
		git checkout somebranch^0
	)

See [1] for caveats and future directions.

[1] http://thread.gmane.org/gmane.comp.version-control.git/150559
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help