I have modified my source directory by deleting certain files and done a commit
. And I did a push origin master
to remote host, github.
Now I came to know that I need those files for proper functioning. Now I need a way to go back my prev commit
and then push
to my remote host.
Is it possible to do so? I'm very new to git, I'm confused with it.
Thanks in advance.
Since you've already pushed, I would recommend against Nikhil's solution and recommend that you do a "git revert" on your latest commit like so git revert HEAD
and then push. The revert
command will create a new commit that undoes the effect the specified commit and adds it to your repository.
git revert
creates a new commit that undoes one or more previous commits. This is usually the best way to undo commits that have already been pushed.
For example, this command would revert everything from the commit abc1234
up to and including the latest commit ( HEAD
):
git revert abc1234..HEAD
You could also use git reset
, but this command changes history and would cause problems for anyone else who is using the repository. In general you should only use this command if you want to discard changes that haven't been pushed (and that you're sure you won't want to come back to in future).
Try on of these,
git reset --hard SHAsumOfYourCommit
git reset --hard HEAD [your current head point]
git reset --hard HEAD^ [your previous head point]
Let's say we have a remote myrepo with branch master that currently points to commit dd61ab32, you can remove the last commit byusing the command.
git push myrepo +dd61ab32^:master
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.