简体   繁体   English

Git 在没有 .git 目录的情况下复制存储库时,也会复制历史记录

[英]Git history is copied too when a repository is copied without the .git directory

I am trying to copy all the files in a public git repository, let's call it repo_A, into a completely new private git repository, let's call it repo_B.我正在尝试将公共 git 存储库(我们称之为 repo_A)中的所有文件复制到一个全新的私有 git 存储库(我们称之为 repo_B)中。
As far as I know, git init --template will not fit that need.据我所知, git init --template不适合这种需要。 I currently run this set of terminal commands:我目前运行这组终端命令:

git clone repo_A_clone_link  
git clone repo_B_clone_link
cp -a ./repo_B/.git/. ./repo_A/.git/  
cp -a ./repo_A/. ./repo_B/   
cd ./repo_B 
git push

The push is successful, and I see all the files from repo_A in repo_B's master branch.推送成功,我在 repo_B 的 master 分支中看到了 repo_A 的所有文件。
The problem is for some reason, I still see repo_A's commit history in repo_B.问题是出于某种原因,我仍然在 repo_B 中看到 repo_A 的提交历史。

I tried to read about the subject and investigate, but according to this question it seems that the fact repo_B's .git directory did not change should mean its history won't change either.我试着阅读这个主题并进行调查,但根据这个问题,repo_B 的.git目录没有改变的事实似乎意味着它的历史也不会改变。

Also went through this question , that one and several others.还经历了这个问题那个问题和其他几个问题。

What am I missing here?我在这里错过了什么? How can I prevent the history from being copied as well?我怎样才能防止历史也被复制?
I saw that using --depth 1 might solve it, but I would love to understand what I'm missing from the .git directory perspective.我看到使用--depth 1可能会解决它,但我很想从.git目录的角度了解我缺少的内容。
Thanks!谢谢!

In this case, you did copy the .git directory with cp -a , which operates recursively.在这种情况下,您确实使用cp -a操作复制了.git目录。 The .git directory contains all the history and objects in the repository, and if you copy it from one repository to another, all of the history will be copied as well. .git目录包含存储库中的所有历史记录和对象,如果将它从一个存储库复制到另一个存储库,所有历史记录也将被复制。

If you want to just copy the tracked files, you can use something like this:如果你只想复制跟踪的文件,你可以使用这样的东西:

(cd repoA && git archive --format=tar HEAD) | (cd repoB && tar -xvf -)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM