You essentially tell git that this branch is the template and you want to fill your commits in around the existing commits in this branch. What happens is you rebase “onto” the branch you want to catch up with. Rebase essentially rewrites your git history to put all the commits in their proper place in time. Without all the merge commits, your git history is much easier to read, and is a more accurate record of project progress. But it leaves behind a trace: “Branch so and so has been merged into branch Bob Loblaw.” And sometimes you need finer control over what is in your branch, you want to pull another feature into the branch you’re working on, or you’re just really anal about your git history. Git is an extremely sophisticated program that does some great parsing and does its best to combine unlike things into what you (usually) expect it would. Sometimes, it’s best to just merge and let git do its thing. The answer is kind of complicated and very dependent on style and sensibility. Rebase? Squash? WTF IS THAT!! Why can’t we just merge it? Now rebase and squash that thing and we can merge it in.” Beaming with pride, I messaged my team lead that I had finished the first task handed to me… And he responded “looks good. I hit save, go to my terminal, and type in my commit message. Let’s set the scene: there I am, agonizing over my keyboard, putting the final touches on my masterpiece of a first feature - am I being too dramatic?! ). When I started one of my first professional programming jobs, I was met with a surprise when I put in my first PR. That commit is pulled into your current branch. Git cherry-pick 0d1dsomehashthingycopiedfromgithistory We’re currently in our lovely co-worker’s branch. Whoo, we traveled through spacetime to an imaginary terminal. In our example, you would checkout to your feature branch. This basically lets you copy a specific commit and superglue it on the end of your current branch. Now you reach into your bag of git tricks, and pull out a cherry-pick. What’s that message back from git? Crap, you’re still on your co-workers branch? Type-itty type, you go back to the feature you were working on. Everything looks good you put a comment and a ship emoji on their PR in github and go on your merry way. So at some point in your day, you move from a branch that you’re working on to a teammate’s branch to look at the code they wrote. Say you’re working on a team and you do code review as a part of your process. You can do this for one commit, or a range of commits from a separate branch. What is cherry-pick:Ĭherry-pick essentially pulls changes from a different branch into the current branch you are on. *Photo Credit: The brilliant and hilarious XKCD: Git Cherry-Pickįirst things first, the cherry-pick command.
0 Comments
Leave a Reply. |