0

I pushed to a branch called dev_feature_1 for example, but I'm not supposed to because I'm already finished with feature-1 and I should push to another branch called dev_feature_2 instead.

So I already did push my work to dev_feature_2 successfully, but I want to remove the commit in branch dev_feature_1 as it didn't exist, but I still want my local code to stay the same.

I tried to use revert {hash of the unwanted commit} but it removed everything from local but the remote remained the same! I had to use reset --hard to retrieve back my local code.

All I want is like a delete button on the last commit inside the commits list in GitHub.?

Alaa AbuZarifa
  • 1,171
  • 20
  • 39
  • This may help you to revert this commit.
    [Link](https://stackoverflow.com/a/448929/8116260)
    – Uzair Apr 22 '21 at 22:31
  • 1
    Reverting (with `git revert`) does not *remove* anything. Instead, it adds a new commit that has the *effect* of undoing some previous commit. The previous commit remains, and you can still access it any time you like, and/or copy it to a new commit on a new branch. – torek Apr 23 '21 at 02:11

1 Answers1

-1

Use git revert command to revert the commit

git revert commit_hash_to_reset

git checkout -b your_new_branch

then push the code in your both branch. Remember to add force push flag in your dev_feature_1 branch

Muhammad Ahmed
  • 1,038
  • 1
  • 7
  • 7
  • My code is already pushed to my new branch `dev_feature_2`. when I do revert the last commit from `dev_feature_1` as u suggested, then checkout to the new branch, all the new work is gone from there as well..!! – Alaa AbuZarifa Apr 22 '21 at 22:42
  • 1
    1. Force push is not needed if you you revert, because revert just adds a new commit which un-does the effect of the old commit. 2. Force push should be discouraged because it changes history and anyone who has pulled the old history from the remote will then be out of sync. 3. If you really did revert on dev_feature_1 and then pushed it, and if your feature change really did exist on dev_feature_2 before the revert, then the change still exists on dev_feature_2 – Randy Leberknight Apr 23 '21 at 17:18