From 5851884cdbc5fd42ada67b3138e6589c46dca873 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Thu, 25 May 2023 23:33:39 +0300 Subject: [PATCH] Merge two git snippets --- snippets/git/s/branches-containing-commit.md | 33 ++++++++++++++----- .../git/s/branches-not-containing-commit.md | 22 ------------- 2 files changed, 24 insertions(+), 31 deletions(-) delete mode 100644 snippets/git/s/branches-not-containing-commit.md diff --git a/snippets/git/s/branches-containing-commit.md b/snippets/git/s/branches-containing-commit.md index 2a9060bec..d1fef4426 100644 --- a/snippets/git/s/branches-containing-commit.md +++ b/snippets/git/s/branches-containing-commit.md @@ -1,22 +1,37 @@ --- -title: Find branches containing a commit -type: snippet +title: "Tip: Find branches containing a specific Git commit" +shortTitle: Find branches containing commit +type: tip language: git tags: [branch,commit] +author: chalarangelo cover: dark-leaves -dateModified: 2021-04-13T21:10:59+03:00 +excerpt: Learn how to filter branches based on whether they contain a specific commit or not. +dateModified: 2023-05-25T21:10:59+03:00 --- -Prints all the branches containing a specific commit. +Commits are the building blocks of Git, used to track changes to a repository. They can be used to identify specific points in a repository's history, and can be referenced by their commit hash. But apart from finding a commit, how can you find all the branches containing it? This sort of information can be useful when you want to find out which branches contain a specific bugfix or feature. -- Use `git branch --contains ` to see a list of all branches containing ``. +### Branches that contain a commit + +As usual, Git has a simple solution to this problem. Using `git branch` with the `--contains` flag will print all the **branches containing a specific commit**. ```shell -git branch --contains +# Syntax: git branch --contains + +git branch --contains 3050fc0 +# development +# network-fixes ``` +### Branches that don't contain a commit + +Similarly, you can look for **branches that don't contain a specific commit** by using the `--no-contains` flag. + ```shell -git branch --contains 3050fc0d3 -# patch-1 -# patch-2 +# Syntax: git branch --no-contains + +git branch --no-contains 3050fc0 +# master +# adapter-feature ``` diff --git a/snippets/git/s/branches-not-containing-commit.md b/snippets/git/s/branches-not-containing-commit.md deleted file mode 100644 index a0da47f32..000000000 --- a/snippets/git/s/branches-not-containing-commit.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: Find branches not containing a commit -type: snippet -language: git -tags: [branch,commit] -cover: blue-sunrise -dateModified: 2021-04-13T21:10:59+03:00 ---- - -Prints all the branches not containing a specific commit. - -- Use `git branch --no-contains ` to see a list of all branches not containing ``. - -```shell -git branch --no-contains -``` - -```shell -git branch --no-contains 3050fc0d3 -# patch-3 -# patch-4 -```