我有一个目录gitrepo1.该目录是一个git存储库.
我想将这个gitrepo1移动到另一个目录newrepo.
newrepo应该是新的git存储库,不会丢失git历史记录,并且应该包含目录gitrepo1
gitrepo1现在应该是一个直接的(在newrepo内部),没有任何.git索引.即.它应该不再是一个独立的git存储库或子模块.
我怎样才能做到这一点?
Sha*_*baz 94
这很简单.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
Run Code Online (Sandbox Code Playgroud)
请注意,如果存储库很大且历史很长,则副本非常昂贵.您也可以轻松避免它:
# 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 -
Run Code Online (Sandbox Code Playgroud)
创建后newrepo,要放置的目标gitrepo1可以在任何地方,甚至在内部newrepo也可以.它不会改变程序,只会改变您要写gitrepo1回的路径.
dav*_*pfx 16
它甚至比这更简单。刚刚这样做(在 Windows 上,但它应该适用于其他操作系统):
Git 只是看到您添加了一个目录并重命名了一堆文件。没什么大不了的。
要做到这一点而没有任何头痛:
git status,比方说分支“发展”。git clone是存储库中的项目。git checkout development.rsync,不包括 .git 文件夹:rsync -azv --exclude '.git' gitrepo1 newrepo/gitrepo1。你rsync当然不必这样做,但它做得非常顺利。您很高兴从上次中断的地方继续:您的旧分支、未暂存的更改等。
| 归档时间: |
|
| 查看次数: |
114768 次 |
| 最近记录: |