Pregunta

I'm looking at the last 10 or so pushes, and I would like to back out 4 of them (unconsecutive).

How can I do this?

In SVN, it would be a matter of reverting the changes and pushing the "undone" changes back in. Not sure how to do it in Git.

¿Fue útil?

Solución

You use git revert <commit> to revert the offending commits without rewriting history. This creates a new commit that undoes these commits.

Instead of <commit> you use the SHA of each commit you want to revert.

Otros consejos

@ThiefMaster's answer works great.

As an alternative, if it's not a shared remote branch (meaning if no one else has pulled your changes) you could git rebase -i HEAD~10. This will open a list of the last 10 commits in your $EDITOR. Just delete the commits you no longer want, save the file, and git push -f to force push and overwrite the history on the remote branch.

Advantage: it's leaves the history cleaner.

Disadvantage: you might not want the history cleaned up and could desire having the revert commits captured in the git history.

More on interactive rebasing here: http://git-scm.com/book/en/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top