如何清除存储库的提交历史记录?

How to clean the commit history of a repository in both of my locally cloned copy and the copy on the git server so that only the files after the last commit are left?

如何清除本地克隆副本和git服务器上副本中存储库的提交历史记录,以便仅保留最后一次提交后的文件

git works in branches. Here, we assume removing the history of the master branch. One solution is doing as follows.

git在分支中工作。 在这里,我们假设删除master 分支的历史记录。 一种解决方案如下。

Rename the current master.

重命名当前的母版。

git checkout --orphan newbranch

Add all files back. If you would add only some files, add them separately.

重新添加所有文件。 如果仅添加一些文件,请分别添加它们。

git add -A

Commit the change of adding files.

提交更改添加文件。

git commit

Delete the master branch.

删除master分支。

git branch -D master

Rename the current newmaster branch to be master.

将当前的newmaster分支重命名为master。

git branch -m master

Force pushing the master branch to the git server.

强制将master分支推送到git服务器。

git push -f origin master

(Optional) Let git garbage collect unnecessary files in the local repository

(可选)让git垃圾收集本地存储库中不必要的文件

git gc --aggressive --prune=all

翻译自: https://www.systutorials.com/how-to-clean-commit-history-of-a-repository/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值