使当前提交Git仓库中唯一的(初始)提交? [英] Make the current commit the only (initial) commit in a Git repository?

查看:88
本文介绍了使当前提交Git仓库中唯一的(初始)提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



本地存储库有10个提交,并且Github存储库是一个同步重复。



我想要从本地Git存储库中删除所有版本历史记录,因此存储库的当前内容显示为唯一的提交(因此存储库中旧版本的文件不会被存储)。



然后我想将这些更改推送到Github。



我调查了Git rebase,但是这似乎更适合删除特定版本。
另一个可能的解决方案是删除本地仓库,并创建一个新仓库 - 尽管这可能会产生很多工作!



ETA:有特定的目录/文件未跟踪 - 如果可能的话,我想保留这些文件的解开。

解决方案

这是暴力做法。它还会删除存储库的配置。



注意:如果存储库具有子模块,则这不起作用!如果你使用子模块,你应该使用例如互动式重新组合



第1步:删除所有历史记录(确保您有备份,这是无法恢复的状态)

  rm -rf .git 

第2步:重建只有当前内容的Git回购

  git init 
git add。
git commit -m初始提交

第3步:推送到GitHub。 p>

  git remote add origin< github-uri> 
git push -u --force原始大师


I currently have a local Git repository, which I push to a Github repository.

The local repository has ~10 commits, and the Github repository is a synchronised duplicate of this.

What I'd like to do is remove ALL the version history from the local Git repository, so the current contents of the repository appear as the only commit (and therefore older versions of files within the repository are not stored).

I'd then like to push these changes to Github.

I have investigated Git rebase, but this appears to be more suited to removing specific versions. Another potential solution is to delete the local repo, and create a new one - though this would probably create a lot of work!

ETA: There are specific directories / files that are untracked - if possible I would like to maintain the untracking of these files.

解决方案

Here's the brute-force approach. It also removes the configuration of the repository.

Note: This does NOT work if the repository has submodules! If you are using submodules, you should use e.g. interactive rebase

Step 1: remove all history (Make sure you have backup, this cannot be reverted)

rm -rf .git

Step 2: reconstruct the Git repo with only the current content

git init
git add .
git commit -m "Initial commit"

Step 3: push to GitHub.

git remote add origin <github-uri>
git push -u --force origin master

这篇关于使当前提交Git仓库中唯一的(初始)提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆