简体   繁体   English

将Git repo克隆到新的repo中 - 没有提交历史记录

[英]Cloning a Git repo into a new repo - without commit history

So I'm trying to get my head around Git, and have the need (why I have this need I won't go into) to be able to take the files from one repo, via command line, and put them into a brand new repository WITHOUT taking all of the previous commit history with it. 所以我试图让我的头围绕Git,并且有需要(为什么我有这个需要我不会进入)能够通过命令行从一个仓库获取文件,并将它们放入一个品牌新存储库没有获取所有以前的提交历史记录。

What I'm trying to do at the moment is git init to create a new repository, and then grab the files from my existing repo, either using clone or subtree (I've not got my head fully around this yet so may be barking up the wrong tree), and then add, commit, and then push these to my new repository. 我现在要做的是git init创建一个新的存储库,然后从我现有的repo中获取文件,使用克隆或子树(我还没有完全绕过它,所以可能会吠叫错误的树),然后添加,提交,然后将这些推送到我的新存储库。

git init
--- get the files from stock repo ---
git add .
git commit -m 'Initial commit'
git remote add origin <url of my new repo>
git push -u origin master

My repositories are all on Bitbucket, if that makes a difference, 我的存储库都在Bitbucket上,如果这有所不同,

You can clone the old repository like: 您可以克隆旧存储库,如:

git clone git@bitbucket.org:username/repository.git

and then you delete the git directory: 然后删除git目录:

rm -rf .git/

Now you create the new repository: 现在您创建新的存储库:

git init

If you have those files from stock repo cloned somewhere, you can do a: 如果您在某处克隆了库存回购中的那些文件,您可以执行以下操作:

cd yourNewRepo
git --work-tree=/path/to/stock/repo add .
git commit -m 'Initial commit'

That means: you are considering the files from /path/to/stock/repo as your working tree for your new repo (just for the git add step) 这意味着:您正在考虑将/path/to/stock/repo作为新repo的工作树(仅适用于git add步骤)

Once the index of your new repo has recorded those files, you can forget about the stock repo, and commit those new files (without any prior history) in your new repo. 一旦您的新仓库的索引记录了这些文件,您就可以忘记库存仓库,并在新仓库中提交这些新文件(没有任何先前的历史记录)。

If you've already got the TMI repo cloned you can reset your clone's master to have only that one's tip commit for history with 如果你已经克隆了TMI repo,你可以重置你的克隆的主人只有那个提示的历史提交

git branch -f master `git commit-tree -m "My new initial commit" origin/master^{tree}`

and then do as usual, fix up the remotes and push histories around as as you like. 然后像往常一样,修复遥控器并按照您的喜好推动历史。

( edit : if you've got master checked out git branch won't want to rewrite the ref, but you're not touching the content at all, so you can bypass all the porcelain's handholding and just do it 编辑 :如果你有主人检查过git branch不想重写ref,但你根本没有触及内容,所以你可以绕过所有瓷器的手持操作然后去做

git update-ref -m "Truncating history" refs/heads/master \
        `git commit-tree -m "My new initial commit" origin/master^{tree}`

)

  1. You clone the old repository like: 您克隆旧存储库,如:

    git clone git@bitbucket.org:username/repository.git

  2. Then you delete the git directory: 然后删除git目录:

    rm -rf .git

  3. Create the new repository: 创建新存储库:

    git init

  4. Commit the new repository and push it to the master origin 提交新存储库并将其推送到主源

    git push -u origin master

If possibele, check the status of the git log to verify you have the correct info logged. 如果可能,请检查git日志的状态以验证是否记录了正确的信息。

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

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