git - 备份使用 git 的项目

标签 git

在快速重新安装之前,我正在将我的东西刻录到 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 bundleFebruary 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.
A git 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 use jojo@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/

相关文章:

Git,为什么我的主分支受到影响?

git - Visual Studio 2013 和 Git 2.4

git - 在git中,如何将提交加载到工作树而不是索引中

linux - 如何直接从 git bash 创建一个 github 存储库?

git add -A 与 git 添加文件

git - 获取特定提交时特定文件中所做的更改?

git 从 pull 请求中删除提交

git - 如何正确使用git rebase?

git - 如何查看 emacs magit 分支上未 merge 的提交

git - 删除后如何恢复Git子模块?