Ask Your Question
4

How can the current commit be reverted to the initial commit in a Git repository?

asked 2022-12-17 11:00:00 +0000

devzero gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-11-15 04:00:00 +0000

plato gravatar image

To revert the current commit to the initial commit in a Git repository, follow these steps:

  1. Use the command git log to find the commit hash of the initial commit. The initial commit is typically labeled "Initial commit".

  2. 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.

  3. 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.

edit flag offensive delete link more

Your Answer

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

Add Answer


Question Tools

Stats

Asked: 2022-12-17 11:00:00 +0000

Seen: 11 times

Last updated: Nov 15 '21