How to reset commit of remote branch? (use git command)
Clash Royale CLAN TAG#URR8PPP
How to reset commit of remote branch? (use git command)
How to reset commit of the remote branch? (use git command)
The situation is this,
branch A
git add modify files
git commit -m "ISSUE FIX A"
git push origin A
Found problems from ISSUE FIX A commit, so I want to reset this commit
git reset HEAD^
git commit -m "Reset commit HEADNUM"
git push origin A
then error message
! [rejected] BRANCH A -> BRANCH A (non-fast-forward)
Please let me know any solution.. thanks
5 Answers
5
Just fix the issue on your local, save it and:
git add .
git commit --amend --no-edit
git push --force-with-lease
The commit and its hash will change keeping the same commit message. The --force-with-lease
overwrites your remote branch with your local, unless someone else committed on it.
--force-with-lease
Because you are trying to edit the history, you need to use git push --force origin A
.
git push --force origin A
Although this should only be done if you are pushing to your own pull request, or somewhere that people will not be surprised if the history changes.
By the way, you can amend your commit without using git reset
by using git commit --amend
to amend the last commit.
git reset
git commit --amend
Thanks for the answer, but I can't do this because have no permission
– Beginner Developer
Aug 10 at 6:13
In that case you cannot reset it. You should make a new commit to fix the changes, or make a new pull request (if you are making a pull request).
– Adam Millerchip
Aug 10 at 6:15
you want to add some more changes to that last commit, you can simply stage them as normal and then commit again:
$ git add some/changed/file.ext
$ git commit --amend -m "commit message"
or you can Hard and Soft commands :
neither produces any new commits nor does it delete any old ones. It works by resetting your current HEAD branch to an older revision (also called "rolling back" to that older revision):
$ git reset --hard Commit ID
After this command, your currently checked out branch will be at revision commitID. The commits that came after this one are effectively undone and are no longer visible in the history of this branch.
Be careful, however: calling the command with the "--hard" option will discard all local changes that you might currently have. The project is completely restored as it was in that past revision.
If you call it with "--keep" instead of "--hard", all changes from rolled back revisions will be preserved as local changes in your working directory.
NOTE: If this is a public branch
repository used by others, its your responsibility to inform about your changes. So they can perform a reset with origin.
branch
For Local: git reset --hard z99909W
z99909W is the commit id found in bitbucket.
git reset --hard z99909W
For Repository: git push --force origin z99909W:branchA
git push --force origin z99909W:branchA
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Possible duplicate of Changing git commit message after push (given that no one pulled from remote)
– gazdagergo
Aug 10 at 6:30