In this quick tutorial I want to show you how to split a commit into multiple parts the easy way. ![]() Maybe you want to move the changes done to b.txt to another commit, in order to make your history clearer. Then, hours and many commits later, you realize that changes done to b.txt should not be part of that commit. At some point you create a commit that include, say, changes to files a.txt, b.txt and c.txt. However, other users sharing the branch can be confused if the branch is shared on remote repositories.Imagine you are working with multiple files in a Git-managed project. The consequences of any "accident" can be reverted by using the proper commit. Resets on local branches are usually harmless. Unreferenced commits remain in the repository until the garbage collection software is run by system. They would still be in the repository if we did not tag them, but then we could reference them only by their hash names. They are not listed in the master branch anymore but still remain in the repository. We can see that the wrong commits are not gone. * 45fa96b | Revert "Oops, we didn't want this commit" (oops) Run: git hist -all Result: $ git hist -all At the beginning of the lesson, we created the "oops" tag for the canceled commit. What happened to the wrong commits? They are still in the repository. The -hard parameter makes the working directory reflect the new branch head. Our master branch is pointing at commit v1 and the "Revert Oops" and "Oops" commits no longer exist in the branch. * fa3c141 | Added HTML header (HEAD, v1, master) As the branch has a tag, we can use the tag name in the reset command (if it does not have a tag, we can use the hash value). In the history log above, the commit tagged "v1" is before the "Oops" and "Revert Oops" commits. Run: git tag oops 04 Reset commit to previous Oops Let us mark the last commit with tag, so you can find it after removing a commit(s). Let us remove them with the reset command. ![]() ![]() We see the last two commits in this branch are "Oops" and "Revert Oops". * 8c32287 | Added standard HTML page tags (v1-beta) * 846b90c | Oops, we didn't want this commit * 45fa96b | Revert "Oops, we didn't want this commit" (HEAD, master) Let us do a quick scan of our commit history. Optionally reset the working directory so it will match the specified commit. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |