Suppose there are two branches, feature1 and feature2, and you want to apply commits from feature1 to feature2. That's where cherry-picking commits to the working version can be a savior. When multiple developers are working on the same codebase, it is very likely for changes to get lost and the latest version to move to a stale or non-working version. Undoing/restoring lost changesĬherry-picking can be handy when you want to restore to a working version. This explains why you get a unique commit hash for the slightest change you make to your code. This hash represents the string commit.Ī SHA-1 hash generated by Git when you make a commit represents much more than just a single string. If you are on a POSIX system, try running this in your terminal: $ echo -n "commit" | openssl sha1 The SHA-1 algorithm takes an input and outputs a unique 40-character hash. In case you are wondering what a commit hash is and how it is generated, here is a note to help you: A commit hash is a string generated using the SHA-1 algorithm. Please note that cherry-picking commits will create a fresh commit with a new hash in the other branch, so please don't be confused if you see a different commit hash. There's no need to redo the same changes in a different branch when you can just copy the same commits to the other branch. There are various reasons to use cherry-picking. As the term suggests, you can use it to hand-pick a commit from one branch and transfer it into another branch. Here is where cherry-picking comes into play. So, is there a way? Yes, Git's got you covered. Wait, the former is too tedious, and you may not want to do the latter. Suppose you have made several commits in a branch, but you realize it's the wrong branch! What do you do now? Either you repeat all your changes in the correct branch and make a fresh commit, or you merge the branch into the correct branch. Here is an example to help you understand the importance of cherry-picking. Git is powerful and makes you feel in control-there is not a single way in which you cannot revert to a working version. It can be massively overwhelming for a newbie, but being well-versed with the terminology and the basics of a version control system like Git is one of the baby steps to start contributing to open source.īeing familiar with Git can also help you out of sticky situations in your open source journey. Finding your way around a version control system can be tricky.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |