![]() If you're cherry-picking a lot of commits out of order, those commits will be recorded in your branch, and it might lead to undesirable results in your Git branch.Ĭherry-picking is a powerful command that might cause problems if it's used without a proper understanding of what might occur. The primary reason is that it creates duplicate commits, but you also lose the ability to track your commit history. Push your changes to your remote server, and you're done! Reasons to avoid cherry-pickingĬherry-picking is usually discouraged in the developer community. The second commit is now in your repository: $ cat fruit.txt You want to accept the second commit but not the third, so use cherry-pick: $ git cherry-pick 0664292 You've fetched the commits from your imaginary developer, but you haven't merged them into your repository yet. $ git log –oneline dev/masterĮ858ab2 Added a vegetable that tastes like a fruit Remote: Total 6 (delta 0), reused 0 (delta 0) Remote: Compressing objects: 100% (2/2), done. Return to your authoritative repo and fetch the commits from your imaginary developer: $ cd ~/fruit.git $ git commit -m 'Added a vegetable that tastes like a fruit" Now, create a bad commit to represent something you wouldn't want to merge into your project: $ echo "Rhubarb" > fruit.txt Now, represent a remote developer by creating a fork of your project: $ mkdir ~/fruit.fork To try the process, launch a terminal and generate a sample project: $ mkdir fruit.gitĬreate some data and commit it: $ echo "Kiwifruit" > fruit.txt There's no doubt that git pull is convenient, but it's imprecise. The cherry-pick command is a tool you use to specifically not do that instead, use git fetch, which fetches commits but does not apply them. When cherry-picking commits, you can't use the git pull command because it fetches and automatically merges commits from one repository into another. If you would like to select more than one commit simultaneously, add their commit hashes separated by a space: $ git cherry-pick hash1 hash3 The syntax is: $ git cherry-pick -no-commitįor example: $ git cherry-pick 65be1e5 -no-commit If you'd like to make further modifications, you can also instruct Git to add commit changes to your working copy. This will dedicate the specified change to your currently checked-out branch. Once you know the commit hash, you can use the cherry-pick command. To get the commit hash, you can use the git log command: $ git log -oneline In the cherry-pick command's simplest form, you can just use the SHA identifier for the commit you want to integrate into your current HEAD branch.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |