简体   繁体   中英

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.
As far as I know, git init --template will not fit that need. 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.
The problem is for some reason, I still see repo_A's commit history in repo_B.

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.

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.
Thanks!

In this case, you did copy the .git directory with cp -a , which operates recursively. 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.

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 -)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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