![]() And in case your repo doesn't want to remove the commit ("no fast-forward allowed", which happens when you want to remove a commit you already pushed), you can use git push -force to force push the changes. Note: of course, all these changes are done locally, you should git push afterwards to apply the changes to the remote. ![]() Yet another alternative: git revert -no-commitĪs a last resort, if you need full freedom of history editing (eg, because git don't allow you to edit what you want to), you can use this very fast open source application: reposurgeon. Quick rebase: remove only a specific commit using its id: git rebase -onto commit-id^ commit-idĪlternative: you could also try: git cherry-pick commit-id Interactive rebase (this will show the log of the last 5 commits and delete the lines you don't want, or reorder, or squash multiple commits in one, or do anything else you want, this is a very versatile tool): git rebase -i HEAD~5Īnd if a mistake is made: git rebase -abort If -soft does not work, rather try -mixed or -keep. Note: Avoid git reset -hard as it will also discard all changes in files since the last commit. Harsh way, remove altogether only the last commit: git reset -soft "HEAD^" Note: if the commit to remove is a merge commit, you will need to append -m 1 (thanks to for the tip!). There are four ways of doing so (replace "commid-id" with your commit's hash):Ĭlean way, reverting but keep in log the revert: git revert -strategy resolve commit-id ![]() Mark the corrected paths with 'git add ' or 'git rm ' Here is an example of how I have been trying to revert $ git revert 342f9bbĪutomatic revert failed. Initialized empty Git repository in /Users/josh/deleteme/git_revert_test/.git/ġ files changed, 1 insertions(+), 0 deletions(-) Given the following scenario, how do I remove commit 2? $ mkdir git_revert_test & cd git_revert_test So here is a simplified version of the question: I've been looking and playing for a long time, trying to figure out how to remove the commits that contain the edits to those files, it seems to be a toss up between revert and rebase, and there are no straightforward examples, and the docs assume I know more than I do. Somehow I merged his work into mine, either when I pulled it, or when I tried to just pick the specific files out that I wanted. I was working with a friend on a project, and he edited a bunch of files that shouldn't have been edited.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |