To revert the current commit to the initial commit in a Git repository, follow these steps:
Use the command git log
to find the commit hash of the initial commit. The initial commit is typically labeled "Initial commit".
Use the command git reset --hard <commit-hash>
to reset the repository to the initial commit. Replace <commit-hash>
with the hash of the initial commit that you found in step 1.
Use the command git push --force
to force push the changes to the remote repository. This will overwrite any changes made after the initial commit, so make sure you have a backup of any changes you want to keep.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2022-12-17 11:00:00 +0000
Seen: 11 times
Last updated: Nov 15 '21
How can I commit only files that were modified in Git, not files that were deleted?
Git: Is it a good Idea to add the same Submodule multiple times as Submodule a Submodule?
How can I speed up a large Git Repository with lots of Directories?
How can I check out a Branch in Git?
Is it possible to refresh the index when Git stash pop requires merging?