The first option is the most obvious one: run the revert command onto the commit hash we're reverting to. If you scroll through this and everything looks good, it's time to obliterate those commits! Step 4 Option 1: Run a commit revert (recommended) Otherwise, the diff will stop one commit early. This makes sure we diff down to the ancestor of that commit hash. So, everything in green is what will be added after reverting, and everything in red will be removed.Īlso note the ^ at the end there. Note this is from the perspective of changing from our most recent commit to the commit we're reverting to. Next, we see a line-by-line breakdown of lines added and removed from each modified file. In this case, the the resolution of a few images were updated. These files are often editor / build specific files (as in. First, we see a log of all binary files changed, with paths listed as a/file_path and b/file_path. To do so, use the copied hash and run the following command: git diff HEAD COPIED_HASH^ This is very vim so I don't blame you if you got stuck here □ Step 3: Diff against the most recent commitĬhecking for differences against your revert point is a great way to verify what changes you're about to make. Note: You can exit this log by hitting the "q" key. Once you find the inflection point for your code explosion, copy the hash for that commit and move on to the next step. These are hashes which uniquely identify a given commit. It also shows branch points to see the history of everything that got merged.Īlso notice the alphanumeric strings to the left of each commit. This will show all of the commit history for your branch, starting with the most recent. The cleanest way to do so is using: git log -oneline and out through the mouth.īefore doing anything you might regret, it's best to look through all recent commits to pinpoint where you're reverting to. Before frantically flying to the keyboard, just go in through the nose. Git version 2.16 formally deprecated the old verb (though it still works in Git 2.23, which is the latest release at the time I am editing this).The best way to overcome your escalating fear that your codebase / world is collapsing around you is deep breathing. Git version 2.13 introduced the new verb to make things more consistent with pop and to add more options to the creation command. (This does of course introduce another point where you can take another coffee break and forget what you were doing, come back, and do the wrong thing, so it's not a perfect cure.)ġThe save in git stash save is the old verb for creating a new stash. That's why I recommend separate apply, inspect results, drop only if/when satisfied. That's fine as far as it goes, but it means that if the application results in a mess, and you decide you don't want to proceed down this path, you can't get the stash back easily. Many people use git stash pop, which is short-hand for git stash apply & git stash drop. So it's a good idea to inspect the results carefully before you assume that the stash applied cleanly, even if Git itself did not detect any merge conflicts. This means you can get "merge conflicts" if the branch you were working on by mistake, is sufficiently different from the branch you meant to be working on. The apply step does a merge of the stashed changes, using Git's powerful underlying merge machinery, the same kind of thing it uses when you do branch merges. (They're still in the repository, and can sometimes be retrieved in an emergency, but for most purposes, you should consider them gone at that point.) This deletes the reference to the weird non-branch-y commits. If all goes well, and you like the results, you should then git stash drop the stash. Switch branches, then "apply" the stash: $ git checkout develop The commits it makes are not "on" anyīranch but are now safely stored in the repository, so you can now This commits your code (yes, it really does make some commits) usingĪ weird non-branch-y method. Run git stash save or git stash push, 1 or just plain git stash which is short for save / push: $ git stash The easiest is probably git stash (as all the other answer-ers If not ( error: Your local changes to the following files would be overwritten. Now you can commit and the new stuff is all on develop. This creates a new develop branch starting from wherever you are If you don't have a develop yet, the method is trivial: $ git checkout -b develop So now you want these changes, which you have not yet committed to master, to be on develop. return, edit a bunch of stuff, then: oops, wanted to be on develop Let's take a classic mistake: $ git checkout master There are a bunch of different ways depending on how far along you are and which branch(es) you want them on.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |