0

I have the following Git log.:

Git log

I have used the EGit "Amend previous commit" function to change the commit message for commit with message "Remove unused function addSubinterval before", that I have already pushed to the Git server to "Remove unused function addSubinterval".

After that I realized that I have code back in my file, that I have removed and pushed to the server. It was commit with message: "Remove unused function setDocumentTextAndInfoColor()". I don't know if it's only content from this commit is back.

I checked commit with message: "Delete "nextrefid" and "nextrefid_nr" for follow-on...". That commit is not restored in my local file.

Is that a desired behaviour for "Amend previous commit"?

I guess it is a bug, but maybe I miss something?

BuZZ-dEE
  • 6,075
  • 12
  • 66
  • 96

1 Answers1

0

Amend replaces your last local commit with a modified one. But in your case, you already pushed the original commit to your server. In that case, EGit even warns you:

EGit warning on amend of pushed commit

I suspect what you did later was "Pull". This merges the remote branch origin/master with your local branch master. In your case, this means that the original commit was merged back to your local branch, that is why you still see it in the history.

If you actually want to remove the original commit from the server, you will have to use what's called a "force push". It is called like that because what you're effectively doing is overwriting/removing data on the server. If other people already have the original commit (they fetched after you pushed), you will also have to coordinate with those people so that they can remove the commit from their local repository as well.

For these reasons, it's not recommended to amend commits after they have been pushed (except in special workflows such as Gerrit, or if you know what you are doing).

robinst
  • 30,027
  • 10
  • 102
  • 108