-2

Just trying to remove the commit here as I've doubled up and I've correct somethings which should not be here example below. example

Just want to delete the top commit so it doesn't show up, I know how to revert or checkout to a previous but cant remove that top commit.

cheers

Nathan
  • 1
  • 3

1 Answers1

-1

this solution i strongly advise to be carefull if you are working with a team

Here is a simple approach in up to 4 steps:

0 - Advise the team you are going to fix the repository

Connect with the team and let them know of the upcoming changes.

1 - Remove the last commit

Assuming your target branch is master:

$ git checkout master # move to the target branch
$ git reset --hard HEAD^ # remove the last commit
$ git push -f # push to fix the remote
At this point you are done if you are working alone.

2 - Fix your teammate's local repositories

On your teammate's:

$ git checkout master # move to the target branch
$ git fetch # update the local references but do not merge
$ git reset --hard origin/master # match the newly fetched remote state

If your teammate had no new commits, you are done at this point and you should be in sync.

3 - Bringing back lost commits

Let's say a teammate had a new and unpublished commit that were lost in this process.

$ git reflog # find the new commit hash
$ git cherry-pick <commit_hash>
lucho20pt
  • 77
  • 5
  • ok yes but will that show in the history that the commit is gone like in the example photo? or can you not change that – Nathan Apr 27 '21 at 10:49