在快速重新安装之前,我正在将我的东西刻录到 DVD 上。作为最近的用户,从来没有用 git 做过。所以我只是和你们核实一下。如果我理解正确的话,我只需要备份我的项目目录 project_name(里面有 .git),看是否有 stash 文件,当我把它复制到"new"机器上时,再次安装 git,我像什么都没发生一样恢复?正确吗?
最佳答案
如果你只想备份项目文件(没有历史),你可以使用git archive
(这样,我就不必“监视 stash 文件”)
脚本git-archive-all.sh
实际上会归档当前路径中的所有 git 存储库和子模块。
Useful for creating a single tarfile of a git super-project that contains other submodules.
作为Charles Bailey在评论中正确提到, git bundle
更合适,保留历史。 (git bundle
在 February 2007 中引入)。
参见 Backing up a git repository with git bundle
git bundle
was designed to allow transfer of git commits when there is no direct connection between repositories (i.e.: offline) but using patches is not an option because of the large number of commits and multiple branches.
Agit bundle
is just one file which can be very easily created and again imported as it can be treated like another remote. A quick example:
jojo@dualtron:~/devel$ git bundle create ~/devel.bdl master test
and a bundle is saved under
~/devel.bdl
containing my master and test branches.
If I am now at repository B I just usejojo@dualtron:~$ git ls-remote devel.bdl
which shows me the branches stored in the bundle.
To use the bundle I simple treat it like a remote, using git fetch (for example)
jojo@dualtron:~/git/repoB$ git fetch ~/devel.bdl refs/heads/\*:refs/remotes/bundle/\*
关于git - 备份使用 git 的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2046918/