checkout to other directory (Re: [PATCH 3/3] setup: always honor GIT_WORK_TREE and core.worktree)
- From
Jonathan Nieder <jrnieder@gmail.com>
- Date
- Jan 19, 2011, 20:52 UTC
- Message-ID
- <20110119205257.GA31029@burratino>
- In-Reply-To
- <4D374B04.80500@seznam.cz>
Maaartin wrote:
Show 10 quoted lines
> 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