In this step, we will create a new branch and make a commit on it that is not based on the commit pointed to by our v1.0
tag. This will help us understand how git branch --contains
behaves with branches that do not contain the specified commit.
First, let's create a new branch called feature-branch
.
git branch feature-branch
Now, let's switch to this new branch.
git checkout feature-branch
You should see output indicating that you have switched branches:
Switched to branch 'feature-branch'
Next, let's make a new commit on this feature-branch
. We'll create a new file.
echo "This is a new feature" > feature.txt
git add feature.txt
git commit -m "Add new feature file"
You should see output similar to this after the commit:
[feature-branch a1b2c3d] Add new feature file
1 file changed, 1 insertion(+)
create mode 100644 feature.txt
Now, let's use git branch --contains v1.0
again. Remember, v1.0
points to a commit on the master
branch, and our new commit on feature-branch
is different.
git branch --contains v1.0
This time, the output should only show the master
branch:
master
The feature-branch
is not listed because it does not contain the specific commit that the v1.0
tag points to. This demonstrates how git branch --contains
accurately identifies which branches have a particular commit in their history.
This is useful when you want to know if a bug fix (tagged with a version) has been included in a release branch, or if a specific feature (also potentially tagged) has been merged into different development lines.