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/