Hi,
With svn, I was able to run commands on files in a checkout, without having cd
into that checkout first. For example:
# Located in /tmp, running svn operation on /home/d5ve/checkout
d5ve@host:/tmp> svn add /home/d5ve/checkout/myfile.txt
d5ve@host:/tmp> svn diff /home/d5ve/checkout/myfile.txt
d5ve@host:/tmp> svn commit /home/d5ve/checkout/myfile.txt
When I attempt this workflow using git, I get an error:
# Located in /tmp, attempting git operation on /home/d5ve/checkout2
d5ve@host:/tmp> git add /home/d5ve/checkout2/myfile.txt
fatal: Not a git repository (or any of the parent directories): .git
I've tried using the --git-dir
and --work-tree
flags, but that also seemed to fail.
Any suggestions git people? I use this workflow a lot and really miss it when using git.
UPDATE: Based upon lunaryorn answer below, I've created a simple perl script which works out the location of the .git directory from the file paths, and sets the GIT_WORK_TREE and GIT_DIR environmental variables for the command.
Please have a look at: http://github.com/d5ve/rgit
USAGE: rgit COMMAND [ARGS]
Basically just replace git with rgit in a command, and you can run the commands from outside the repository.
cd /tmp
rgit diff /home/d5ve/checkout1
rgit add /home/d5ve/checkout1/rgit.pl
rgit commit /home/d5ve/checkout1/