How do you 'copyout' in Git
I have cases where I need to 'copyout'
an older version (commit) of my code for side by side comparison with my current code.
The action needs to be more than simply swapping between branches, which does not provide concurrent access.
What are the good ways of doing a copyout
of an old commit from Git so that I get an 'off-repo' copy of that old version?
Just to be clear: This is not a cod开发者_开发问答e review style comparison, but comparing the running software with all lights flashing, videos being played, user interactions etc. - hance the need for a full copy.
The git
distribution comes with a contributed script called git-new-workdir
.
You would use it as follows:
git-new-workdir project-dir new-workdir branch
where project-dir is the name of the directory containing your .git
repository.
This script avoids the clone the entire repository approach by setting up a few symlinks.
I'm not sure exactly what you want to do with this file but here are some things that might help you.
- If you simply want to compare files across branches, you can do a
git diff branch1:file branch2:file
to see their differences. - If you want a physical copy of a file that's in the other branch, you can do
git cat-file -p otherbranch:file > tmp
to get it intmp
. You do what you want with it then. - If you want to diff between commits, you can simply say
git diff treeish1 treeish2
to see the differences (where a treeish is a hash, branch, tag etc.). - If you want a physical copy of the repository at the time of a commit completely so that you can take a look, you can do
git archive --format=tar treeish path | (mkdir /tmp/foo && cd /tmp/foo && tar xvf -)
to get an "exported" copy in /tmp/foo. This will not be a version controlled copy. Just a snapshot of the files at the commit pointed to by treeish. - There's also the obvious way mentioned by Beaks which is to make two clones and use them.
Philip, Git doesn't provide a good way to do this, I can only suggest you do the following; assuming "directory-a" is your working-copy.
cd directory-a
git status # make sure it's clean
cd ../
git clone directory-a directory-b
Then you'll have two copies of the repository (this is the recommended Git way) if a simple diff won't do.
You can then revert, merge, branch and mess with both individually without risk or detriment to the other. directory-b
will contain a fresh working copy, taken from directory-a
's status, and won't know about origin
, so it's really just a clone of directory-a
with all history up to that point.
Fun Fact: Some SCM's don't support branching, this is how you branch in those systems.
You can always clone the repository to another location, then rollback that copy of the repository.
You could also delete the files that make it a repository if you truly want it disconnected -- but I doubt you need to do that step.
精彩评论