我很好奇如何删除git中的第一个提交。
在提交任何东西之前,修改是什么?此版本是否有名称或标签?
发布于 2012-06-06 17:27:31
在第一次提交之前没有任何东西,因为每次提交都引用一个父提交。这使得第一次提交是特殊的(孤立提交),所以没有办法引用以前的“状态”。
因此,如果您想修复提交,您可以简单地git commit --amend
:这将修改提交,而不创建另一个提交。
如果只是想重新开始,可以删除.git
存储库,然后使用git init
创建另一个存储库
发布于 2017-07-28 18:47:38
# Check out to a temporary branch:
git checkout --orphan TEMP_BRANCH
# Add all the files:
git add -A
# Commit the changes:
git commit -am "Initial commit"
# Delete the old branch:
git branch -D master
# Rename the temporary branch to master:
git branch -m master
# Finally, force update to our repository:
git push -f origin master
发布于 2019-10-22 13:20:22
我正在寻找一种方法来从repo中撤消所有git提交,就像它们从未发生过一样。
重新设置基数将在一定程度上发挥作用。然而,第一次(按时间顺序是最早的git提交)总是会有问题,因为它没有父级,所以这将会出错。
对我来说,这些答案都不能完全解决这个问题。但是经过大量的搜索和反复的尝试,我发现这是可行的!
git update-ref -d HEAD
git push origin master -f
希望这对你有帮助。祝你今天过得愉快。
https://stackoverflow.com/questions/10911317
复制相似问题