Cleanup pointless commits in GIT

For unknown reason, still can’t remember how to rewrite history in GIT.

Michael Czolko
50 Shades of Programming

--

I'm starting with this ugly GIT history:

2 commits which looks ugly

You know it, sometimes you did some mistake or misspell few words (or worse, you forgot “;” at the end of a line). And you committing like a madman.

Ideal state will be just 2 things. Michael created repository and the first commit with readme file.

Copy readme -> readme2, that's what I did. Second file isn't recognized by GIT, so, I made some kind of backup.

git log

Now I want point GIT to commit 5eb13cf:

$ git push origin +5eb13cf:master

The “ + ” means a forced non-fastforward push.

If you have the master branch checked out locally, you can also do it in two simpler steps: First reset the branch to the 5eb13cf commit, then force-push it to the remote.

$ git reset 5eb13cf —hard$ git push origin master -f

Just move readme2 -> readme. Commit and push:

$ mv README.md2 README.md$ git commit -am"Updating a README."$ git push origin

Done! Result should look like this:

Yeah, that looks pretier

#git

--

--

Michael Czolko
50 Shades of Programming

I'm doing tappity tappity into the computer where code is the outcome.