How to overwrite commit with new on git?

So, I'm working on a sensitive project with a group, and all of our sources are on Github. I recently clicked on a commit, and later realized that there were a lot of mistakes in my push. Since then I have fixed all these errors in my local copy and am going to click again. However, in any way, can I click and overwrite my last commit? My reason is, I do not want others to look for my initial fixation and the changes that she had ...

Basically, I want to rewrite the old commit with my new .. so no information about the old commit is saved for other members of the group.

Any help would be appreciated! Thanks.

NOTE. They just noticed that this question was marked as a duplicate. To clarify, my question is overwriting a commit that has already been pressed. My question is NOT about changing an invalid commit message.

+8
git github
source share
2 answers

Usually, when something comes out on Github (or a public repo), there is no way to make sure anyone else has a bad fix.

If you just want a cleaner code history, the way to do what you ask for is to rewrite the history both locally and in the remote project.

You want to either do git commit --amend to change your old commit, if you haven't created a new commit with your changes yet.

If you already created a new commit, you want to use git rebase -i to crush the commit on top of the old one.

After you make this change locally and verify that your commit looks the way you want, you need to git push --force overwrite the history on the remote Github remote.

Here's a tutorial on rewriting history in git, it explains how the approaches listed in this answer .

+12
source share

I would not advise you to do this since GIT is not intended to remove and / or edit commits. You can simply go back to the previous commit, and then execute the "valid" code again.

Or you can rebase your branch. Or look at the answer .

0
source share

All Articles