简体   繁体   English

git-如何制作一个干净的仓库

[英]git - how to make a clean repository

Setting up a git repository with some messy commits. 用一些混乱的提交建立一个git仓库。 Everything is working and all good, but I would like to remove/delete the messy commits - how do you go about doing that? 一切正常,一切都很好,但是我想删除/删除混乱的提交-您如何去做?

Thanks 谢谢

If you want to go through the entire history, I think the best way would be an interactive rebase 如果您想浏览整个历史,我认为最好的方法是交互式重新定位

git checkout master
git tag oldmaster
git branch newbranch sha1ofRootCommit
git rebase -i newbranch

Your editor should pop up. 您的编辑器应弹出。 Delete the lines of the commits you don't want. 删除不需要的提交行。 If everything goes well and there were no conflicts, master should contain your clean history. 如果一切顺利,并且没有冲突,那么master应该保存您的干净历史记录。

Here is a link to a similar question 这是一个类似问题的链接

As CharlesB said you can squash commits into a single one if you still want to keep the changes by replacing pick with squash instead of deleting the line. 正如CharlesB说可以壁球提交到一个单一的一个,如果你仍然想通过更换保留更改picksquash代替删除线。

Your TREE 您的树

A--B--C--D--E--HEAD 甲 - B - C - d - 电子 - HEAD

If you want to reset to commit C, say the final outcome 如果要重置以提交C,请说出最终结果

A--B--C--HEAD, you can do A--B--C--HEAD,你可以做

git reset --hard <shasum of your commit C>

If you want to remove commit C only, 如果您只想删除提交C,

A--B--D--E--HEAD, you can do A--B--D--E--HEAD,你可以做

git rebase --onto <shasum of B> <shasum of C>

Hope it helps 希望能帮助到你

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

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