开发者

Git: Import Git Index to non-git directory

Let's pretend I have a project directory that isn't a git repository. This project is open source, and it is listed on github. I'd like to update my project directory to the latest repository structure. I could do this by copying the repo's .git/ to my directory, followed by a

git reset --hard

Which would then change the preexisting working directory to match the github repository. Normally, I'd just start fresh by cloning the github repo, but in this case may I have deployment-specific files I'd like keep(which are listed in .gitignore).

I wonder, is there an better way to do this besides manually copyi开发者_开发技巧ng the git index to non-git directory?


A common way to do this is to have a script that does the following:

#!/bin/sh
export GIT_DIR=/srv/git/whatever.git
export GIT_WORK_TREE=/where/to/deploy/
git checkout -f

People often use this in a post-receive hook in a bare repository, so that you can deploy a new version of the application just by pushing to that repository.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜