Skip to content

Commit

Permalink
Cherry-pick example
Browse files Browse the repository at this point in the history
  • Loading branch information
rmarow committed Sep 27, 2023
1 parent 6d8de9a commit 8698585
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 1 deletion.
Binary file removed posts/git-cherry-pick/cherry_pick.jpeg
Binary file not shown.
Binary file removed posts/git-cherry-pick/cherry_pick_chart.jpeg
Binary file not shown.
51 changes: 50 additions & 1 deletion posts/git-cherry-pick/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,53 @@ First it can be useful to look at the branches you have. I did this with the `gi

I use `git lola` which is an alias: `lola = log --graph --decorate --oneline --all`. I highly recommending adding this alias to your `.gitconfig`.

Git throws things away after 2 weeks that are not pushed.
![](lola-1.png)


Here you can see that I have my `HEAD` at `cherry-pick-post`. I have made changes to the about section which I actually wanted to do on the main branch. So I will use `git cherry-pick` to make that happen. First you want to be sure you are on the branch that you want to put the commit on.

![](status-on-cpp-branch.png)

I can see I am on the `cherry-pick-post` branch so I will use `git switch` to go to the main branch.

![](switch-main.png)

Now I am on the desired branch so I can go ahead and `cherry-pick`

I want to use the syntax `cherry-pick <commit>`

![](pick-commit-1.png)

To see what thisdid we will once again do `git lola`

![](lola-after-pick1.png)

Now the `Update about page` commit is on both the `cherry-pick-post` branch and the `main` branch. The commit ID is a new ID on the main branch.

We will now push and look at the gt log again.

![](push-and-lola.png)

At this point `main` appears exactly as we want it to, but `chery-pick`-post` still has the unwanted commit.

So at this point we will once again use the cherry-pick command to mve forward. I will create a new branch called `cherry-pick-1` fro the main branchh.

![](new-branch.png)

Now at this point I want to take everything from the old `cherry-pick-post` branch and pick it to my new branch.

There are 3 commits that I want so I can actually pick them all a once.

`git cherry-pick 9e5da76 463956b 3edb3ee`
![](pick-2.png)

GitHub gives a great summary of what is happening and shows the commits I am picking.
To see where I am at I will do `git lola` once again.

![](lola-2.png)

At this point I have the 3 commits I want on my new branch so I can go ahead and push that branch. `git push -u origin cherry-pick-1`

![](lola-3.png)

Now I no loger want the old branch so I will delete it usingg `git branch -D cherry-pick-post` this will only delete it locally, so you will need to do `git push origin :cherry-pick-post` to delete it from GitHub as well.
Binary file added posts/git-cherry-pick/lola-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added posts/git-cherry-pick/lola-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added posts/git-cherry-pick/lola-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added posts/git-cherry-pick/lola-after-pick1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added posts/git-cherry-pick/new-branch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added posts/git-cherry-pick/pick-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added posts/git-cherry-pick/pick-commit-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added posts/git-cherry-pick/pick2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added posts/git-cherry-pick/push-and-lola.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added posts/git-cherry-pick/status-on-cpp-branch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added posts/git-cherry-pick/switch-main.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8698585

Please sign in to comment.