# this branch in, main will contain all the changes that you want it to. New issue git restore command only in git 2. # You can diff this branch against the main branch to confirm that when you merge # and you can proceed to make any bug fixes or further changes that are required. # This branch will now contain the changes which you originally reverted, Git revert COMMIT_SHA_HASH_YOU_JUST_COPIED # Revert the commit where you reverted the changes. I identified commit 1 as the last time before I merged donorBranch so I did. however, when resolving merge conflicts, things went bad several commits later down the line and I want to go back to the time before I merged from donorBranch. # You'll use this commit SHA hash which you've copied in the next command. I have a repo on myBranch and merged the changes from donorBranch today. Undoing your recent, uncommitted and unstaged changes (preserves history) git restore -staged. Please open an issue or a pull request if you have problems or improvements. When you put git-recover in your PATH, then it becomes a proper git command, and you can run git recover (notice the space instead of the dash). # you created when you reverted the changes e.g. git-recover is a shell script - you can just download it and go. # You need to look at your git log and copy the SHA hash for the commit that # This is where you're going to bring back the changes which were reverted. After that, simply revert to the previous commit using: git checkout In case you don't have the hash ID, you can use the command git reflog.You can find the hash-ID of the previous commit from the command: git log. # Make sure your local main branch is up-to-date. Git Reset A Specific File When invoked with a file path, git reset updates the staged snapshot to match the version from the specified commit. In this case, you can restore the file using either git checkout or git reflog. The following commands assume youâre in a situation where your main branch has had feature-branch merged in, and that the code changes introduced by that merge have then been reverted. Ok, now for the good stuff: the git commands which will restore order to the universe and let you get on with your life. Huh?! Letâs head to the command line and see what that looks like. As long as youâve committed your work in Git, actually losing a file should be quite rare. To bring the changes back in to main which you reverted, as well as any bug fix, you need to create a fresh branch and revert the commit which reverted the changes. Note that this removes all of the subsequent changes to the file, whereas the git revert command undoes only the changes introduced by the specified commit. The reason that the code changes made before the bug fix are "missing" from main when you try to merge feature-branch in again is because the commits containing those changes were already merged in to main earlier.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |