我有一个目录gitrepo1。这个目录是一个git仓库。
我想将此gitrepo1移到另一个目录newrepo。
目录newrepo应该是不丢失git历史记录的新git存储库,并且应包含目录gitrepo1。
目录gitrepo1现在应该只是一个目录(在newrepo内部),没有任何.git
索引,即它不再应该是独立的git存储库或子模块。
我怎样才能做到这一点?
非常简单 Git不在乎目录的名称。它只关心里面的东西。因此,您可以简单地执行以下操作:
# copy the directory into newrepo dir that exists already (else create it)
$ cp -r gitrepo1 newrepo
# remove .git from old repo to delete all history and anything git from it
$ rm -rf gitrepo1/.git
请注意,如果存储库很大且历史悠久,则副本非常昂贵。您也可以轻松避免它:
# move the directory instead
$ mv gitrepo1 newrepo
# make a copy of the latest version
# Either:
$ mkdir gitrepo1; cp -r newrepo/* gitrepo1/ # doesn't copy .gitignore (and other hidden files)
# Or:
$ git clone --depth 1 newrepo gitrepo1; rm -rf gitrepo1/.git
# Or (look further here: http://stackoverflow.com/q/1209999/912144)
$ git archive --format=tar --remote=<repository URL> HEAD | tar xf -
创建后newrepo
,放置目的地gitrepo1
可以在任何地方,即使newrepo
您愿意也可以放置在内部。它不会改变过程,只会改变您正在gitrepo1
回写的路径。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句