patternMinor
How is my branch is one commit behind master
Viewed 0 times
commithowonemasterbehindbranch
Problem
I have a branch and I merged it into the master branch (via Pull Request).Then I un-ticked the box to not delete the branch. Now when I look at the branches this particular branch shows as 1 commit behind the master branch.
I don't understand this, how can it be a commit behind when the commit was what was merged from my branch into master? Is there a way to fix this so that it knows it's the same commit?
I don't understand this, how can it be a commit behind when the commit was what was merged from my branch into master? Is there a way to fix this so that it knows it's the same commit?
Solution
From what you've described, it seems the "one commit" is a merge commit.
This is due to how git works: depending on the steps you performed to get your code merged, it will or will not create a merge commit in the target branch. Check your git history to confirm it.
If that is the case, you can safely ignore it. In a typical git workflow, your "feature branches" are short-lived, getting deleted when merged, so you won't even notice this difference.
If you don't want a merge commit, merging with fast-forward won't produce one, but you may need to rebase (or squash, depending on your preference) the source branch before the merge, which will change your branch history to allow a fast-forward.
Since you've tagged
P.S.: Also, if you are new to git, be extra careful when rewriting history. Things can get messy if you don't know what you are doing. I strongly recommend getting to know git better to get the most out of it.
This is due to how git works: depending on the steps you performed to get your code merged, it will or will not create a merge commit in the target branch. Check your git history to confirm it.
If that is the case, you can safely ignore it. In a typical git workflow, your "feature branches" are short-lived, getting deleted when merged, so you won't even notice this difference.
If you don't want a merge commit, merging with fast-forward won't produce one, but you may need to rebase (or squash, depending on your preference) the source branch before the merge, which will change your branch history to allow a fast-forward.
Since you've tagged
Azure DevOps in your question, you can avoid the merge commit using the "Squash merge" or "Rebase and fast-forward" PR merge types.P.S.: Also, if you are new to git, be extra careful when rewriting history. Things can get messy if you don't know what you are doing. I strongly recommend getting to know git better to get the most out of it.
Context
StackExchange DevOps Q#14301, answer score: 2
Revisions (0)
No revisions yet.