You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: posts/git-cherry-pick/index.md
+11-11Lines changed: 11 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -36,57 +36,57 @@ When using cherry pick it is very important to look at your git log and understa
36
36
37
37
First it can be useful to look at the branches you have. I did this with the `git branch` command and as you can see the one with the asterik and in green is the branch I am currently on.
38
38
39
-

39
+

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

43
+

44
44
45
45
46
46
Here you can see that I have the `cherry-pick-post` branch checked out, as indicated by the `HEAD` ref. 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.
47
47
48
-

48
+

49
49
50
50
I can see I am on the `cherry-pick-post` branch but I want the new commits to be created on `main`, so I will use `git switch` to go to the `main` branch.
51
51
52
-

52
+

53
53
54
54
Now I am on the desired branch so I can go ahead and cherry-pick using the syntax `git cherry-pick <commit>`.
55
55
56
-

56
+

57
57
58
58
To see what this did we will once again do `git lola`:
59
59
60
-

60
+

61
61
62
62
Now the `Update about page` commit is on both the `cherry-pick-post` branch and the `main` branch. Note that the commit ID on the `main` branch is a new ID, but the original commit on `cherry-pick-post` branch has the same ID as before.
63
63
64
64
We will now push and look at the log again.
65
65
66
-

66
+

67
67
68
68
At this point `main` appears exactly as we want it to, but `chery-pick-post` still has the unwanted commit.
69
69
70
70
So at this point we will once again use the cherry-pick command to move forward. I will create a new branch called `cherry-pick-1` from the main branch.
71
71
72
-

72
+

73
73
74
74
Now at this point I want to take everything from the old `cherry-pick-post` branch and pick it to my new branch.
75
75
76
76
There are 3 commits that I want so I can actually pick them all a once.
77
77
78
78
`git cherry-pick 9e5da76 463956b 3edb3ee`
79
79
80
-

80
+

81
81
82
82
Git gives a great summary of what is happening and shows the commits I am picking.
83
83
To see where I am at I will do `git lola` once again.
84
84
85
-

85
+

86
86
87
87
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`
88
88
89
-

89
+

90
90
91
91
Now I no loger want the old branch so I will delete it using `git branch -D cherry-pick-post` this will only delete it locally, so I will also need to do `git push origin :cherry-pick-post` to delete the branch from GitHub.
0 commit comments