From c546d04617d493310040f58e061f357a51b6c208 Mon Sep 17 00:00:00 2001 From: thomasabishop Date: Thu, 6 Apr 2023 14:30:22 +0100 Subject: [PATCH] Autosave: 2023-04-06 14:30:22 --- ..._picking_a_branch.md => Cherry_picking.md} | 21 +++++++++++----- DevOps/Git/Effective_logging_in_Git.md | 13 ++++++++++ DevOps/Git/Git_bisect.md | 25 +++++++++++++++++++ DevOps/Git/Rename_a_branch.md | 2 +- DevOps/Git/Reset_to_remote_version.md | 2 +- _img/cherry-pick.svg | 4 +++ _img/git-bisect.svg | 4 +++ 7 files changed, 63 insertions(+), 8 deletions(-) rename DevOps/Git/{Cherry_picking_a_branch.md => Cherry_picking.md} (62%) create mode 100644 DevOps/Git/Effective_logging_in_Git.md create mode 100644 DevOps/Git/Git_bisect.md create mode 100644 _img/cherry-pick.svg create mode 100644 _img/git-bisect.svg diff --git a/DevOps/Git/Cherry_picking_a_branch.md b/DevOps/Git/Cherry_picking.md similarity index 62% rename from DevOps/Git/Cherry_picking_a_branch.md rename to DevOps/Git/Cherry_picking.md index 0006d63..8ab21af 100644 --- a/DevOps/Git/Cherry_picking_a_branch.md +++ b/DevOps/Git/Cherry_picking.md @@ -15,21 +15,25 @@ Cherry-picking can sometimes result in conflicts, especially if the changes you' ## Syntax -Suppose you have two branches: `main` and `feature`. You want to apply the changes from the commit with hash `abcdefg` from the `feature` branch to the `main` branch. +Suppose you have two branches: `main` and `feature`. You want to apply the changes from the commit with hash `xyx` from the `main` branch to the `feature` branch. -First, switch to the `main` branch: +First, switch to the `feature` branch: ``` -git checkout main +git checkout feature ``` -Next, cherry-pick the commit from the `feature` branch: +Next, cherry-pick the commit from the `main` branch: ``` -git cherry-pick abcdefg +git cherry-pick xyz ``` -This will apply the changes from the commit with hash `abcdefg` to the `main` branch. +This will apply the changes from the commit with hash `xyz` from thee `main` branch to the `feature` branch. This will create a new SHA on `feature` (pqr) but the changes will be identical. + +![](/_img/cherry-pick.svg) + +The benefit is that you only take the select changes you want, you are not merging the whole `main` branch into feature. Note that you can also cherry-pick multiple commits by specifying their hashes separated by spaces: @@ -37,6 +41,11 @@ Note that you can also cherry-pick multiple commits by specifying their hashes s git cherry-pick abcdefg hijklmn opqrst ``` +## Limitations + +- You don't have to just cherry-pick locally, you can also cherry-pick from a [remote tracking branch](/DevOps/Git/Remote_tracking_branches.md). +- You cannot cherry-pick merge commits since these commits do not implement a set of changes, they are connecting commits. + ## Use case The time when I have cherry-picked is when a commit has been reverted via GitHub. This typically happens on the `main` branch when breaking changes have been merged and we want to undo this by reverting back to the previous commit, from before the problematic commit was merged in. diff --git a/DevOps/Git/Effective_logging_in_Git.md b/DevOps/Git/Effective_logging_in_Git.md new file mode 100644 index 0000000..003f21f --- /dev/null +++ b/DevOps/Git/Effective_logging_in_Git.md @@ -0,0 +1,13 @@ +--- +categories: + - DevOps +tags: [git, procedural] +--- + +# Effective logging in Git + +| Root command | Variant | Output | +| ----------------- | ------------ | -------------------------------------------------------- | +| `git log` | filename.txt | List the commits that changed the given file | +| `git log --patch` | filename.txt | Show the diff changes for each commit for the given file | +| `git log --patch` | null | Show the diff changes for each commit for all files | diff --git a/DevOps/Git/Git_bisect.md b/DevOps/Git/Git_bisect.md new file mode 100644 index 0000000..c1dd52d --- /dev/null +++ b/DevOps/Git/Git_bisect.md @@ -0,0 +1,25 @@ +--- +categories: + - DevOps +tags: [git] +--- + +# Bisect + +Bisect can be used to identify commits that introduce a bug or regression in our code. + +It is most useful for when we know there is a problem in the code and we know there was a point in the past where the bug did not exist. We can compare the two points and try to identify where things went wrong. + +We mark the last good revision and the first bad revision. Bisect will the reset the code to the midpoint between the good and bad versions and let you test it. You mark that as a good or bad version and then bisect repeats the process. + +![](/_img/git-bisect.svg) + +## Procedure + +``` +git bisect start + +git bisect good + +git bisect bad +``` diff --git a/DevOps/Git/Rename_a_branch.md b/DevOps/Git/Rename_a_branch.md index 1e7cdb4..956f271 100644 --- a/DevOps/Git/Rename_a_branch.md +++ b/DevOps/Git/Rename_a_branch.md @@ -1,7 +1,7 @@ --- categories: - DevOps -tags: [git] +tags: [git, procedural] --- # Rename a branch diff --git a/DevOps/Git/Reset_to_remote_version.md b/DevOps/Git/Reset_to_remote_version.md index e0e71f3..4f99428 100644 --- a/DevOps/Git/Reset_to_remote_version.md +++ b/DevOps/Git/Reset_to_remote_version.md @@ -1,7 +1,7 @@ --- categories: - DevOps -tags: [git] +tags: [git, procedural] --- # Reset to remote version of a branch diff --git a/_img/cherry-pick.svg b/_img/cherry-pick.svg new file mode 100644 index 0000000..f351da4 --- /dev/null +++ b/_img/cherry-pick.svg @@ -0,0 +1,4 @@ + + + +
main
main
feature
featu...
cherry-pick
cherr...
xyz
xyz
pqr
pqr
Text is not SVG - cannot display
\ No newline at end of file diff --git a/_img/git-bisect.svg b/_img/git-bisect.svg new file mode 100644 index 0000000..200a9c4 --- /dev/null +++ b/_img/git-bisect.svg @@ -0,0 +1,4 @@ + + + +
good
good
bad
bad
bisect
bisect
good
good
bisect
bisect
bad
bad
'bisect' above becomes 'good' below
'bisect' above become...
first stage
first stage
second
 stage
second...
Text is not SVG - cannot display
\ No newline at end of file