![]() ![]() I used git cherry-pick a couple of times and was surprised at how well it went. I had to use cherry picking because of merge conflict that went wrong. If you run git log you'll see the new commit at the top of your log with the author information of the one who made the commit. You did it! You just applied the commit 1a0be4b to your own branch. And see, the commit you needed, is now committed to your branch. It doesn't matter if you use the short or long hash, Git knows what you mean. Now you use the command git cherry-pick 1a0be4b. Git log will give you a long list of all commands, the latest commit will always be on top. In the terminal you can git checkout your-branch-name. If you used git log to find the hash, make sure to switch over to your own branch on which you want the commit your coworker made. This long string of numbers and letters is your hash. You'll get a log of commits made on that particular branch and that will look something like this: commit 1a0be4bfb2b22883528bfe7944298853cb913aa4. The third way, if we're staying in the terminal, is to go to your colleague's branch with the commit you need and use the command git log. Another way is to look at the url of a commit on Github, the last part is the hash. In the commits overview on Github the hash is shown after every commit and exists of 7 digits or letters, for example 1a0be4b. You can find the hash of a commit in multiple ways. Now you need the hash of the right commit and the command git cherry-pick. You and your colleague are both working on separate branches, but your colleague wrote a bit of code that you need on your branch and you can't wait until that pull request is merged. The simplicity of it makes it easier for me to focus on the task at hand. There is a lot of Git software that can make cherry picking as easy as 'drag and drop' but I prefer to use the terminal. I can imagine this all sounds a bit overwhelming, especially when you're like me and you hesitate for a microsecond with actions like git push or merge. It also comes in handy when you made a mistake and can't amend or reset the culprit without having to force push. You could use cherry picking when you only need a couple of commits from another branch, for example a bug fix on a newer branch you can't merge with your own. Now what is cherry picking?Ĭherry picking in Git means you pick only the commits you need and commit these to another branch. Now that I feel more confident doing these, I'll help you get started on the basics too. And when I had to cherry pick a pull request because of a merge gone wrong, I just tried it. Now thanks to working at home with two babies, I work some odd hours and sometimes I need to figure things out myself. I always thought this was some kind of scary tool that was probably really hard, so I never used it. If you work with Git, you've probably heard about it: cherry picking. The non-designer's design book Cherry picking with Git in your terminal ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |