我很好奇如何删除git中的第一次提交。
做任何事情之前的修改是什么?这个修订版有名称或标签吗?
我很好奇如何删除git中的第一次提交。
做任何事情之前的修改是什么?这个修订版有名称或标签吗?
当前回答
如果你只是提交了它,但没有推送它,那么只需删除。git目录并再次init git…
其他回答
# 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
对我来说,最安全的方法是使用update-ref命令:
git update-ref -d HEAD
它将删除命名的引用HEAD,因此它将重置(轻轻地,你不会丢失你的工作)你当前分支的所有提交。
如果你想合并第一次提交和第二次提交,你可以使用rebase命令:
git rebase -i --root
最后一种方法是创建一个孤儿分支,一个具有相同内容但没有任何提交历史的分支,并在其上提交你的新内容:
git checkout --orphan <new-branch-name>
另一种方法是:
签出到你想要保留的分支(比如开发)git签出开发 现在,删除你想重置git分支-D master的分支 现在,创建一个具有相同名称的空分支git checkout—orphan master
当然,所有这些都取决于您的用例,但是如果您有多个分支,删除.git目录就没有意义了。
如果你只是提交了它,但没有推送它,那么只需删除。git目录并再次init git…
您可能只想编辑您的第一次提交(因为在git repo中总是有第一次提交)。考虑使用git commit——modify——reset-author而不是通常的git commit——modify。