(The - makes sure is interpreted as a commit rather than a file the. I ended up using the following steps.įirst, check out the contents of the target commit while leaving HEAD at the tip of the branch: git checkout -f. I was not able to use a series of git revert commands because I eventually ran into conflicts between the reversion changes being added. I was faced with a situation where the commits I needed to roll back were somewhat complex, with several of the commits being merge commits, and I needed to avoid rewriting history. This is an expansion of one of the solutions provided in Jakub's answer. I told the other five guys working in this repository that they better make note of their changes for the last few hours and wipe/rebranch from the latest testing. So forget it I found the last good commit (abc1234) and just ran the basic script: git checkout testing Not only that, but one or two pull requests were accepted, which were now bad. I learned a lot reading Jakub's post, but some guy in the company (with access to push to our "testing" branch without a Pull-Request) pushed like five bad commits, trying to fix and fix and fix a mistake he made five commits ago. I want B, C, D, and HEAD to disappear and I want head to be synonymous with A." git checkout This question says "I want the head of the branch to point to A, i.e. Every other question is in relation to how to revert correctly and preserve history. I'm so frustrated that this question can't just be answered. $ git reset -soft D # (or ORIG_HEAD or ), all of which are D Here it is slightly modified, this way WORKS FOR EVERYTHING: $ git reset -hard A The commit A' has the same contents as commit A, but is a different commit (commit message, parents, commit date).Īlternate solution by Jeff Ferland, modified by Charles Bailey builds upon the same idea, but uses git reset. Then you would have the following situation:Ī <- B <- C <- D <- A' <- master <- HEAD # checkout that revision over the top of local files If you have any local changes git stash them first: $ git checkout -f A. Added files will not be deleted, however. Works for everything except merge commits.Īlternate solution would be to checkout contents of commit A, and commit this state. $ git commit -m "the commit message for all of them" Mathematics tells us that (BCD) -1 = D -1 C -1 B -1, so you can get the required situation using the following commands: $ git revert -no-commit D Where means the commit that reverts changes in commits B, C, D. What you need to create is the following:Ī <- B <- C <- D <- <- master <- HEAD (arrows here refers to the direction of the pointer: the "parent" reference in the case of commits, the top commit in the case of branch head (branch ref), and the name of branch in the case of HEAD reference). You can do this using git revert command. So the solution is to create a new commit which reverts changes that you want to get rid of. If you rewrite (change) history, you would make problems with merging their changes and with updating for them. The general rule is that you should not rewrite (change) history that you have published, because somebody might have based their work on it.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |