What I say below about how Git commits work, and the recommended pre-PR flow, is correct. However, what I say about pull requests is not correct. In the example below, Sabrina's PR would end up with Jasmine's change because a PR merges into master.
My own confusion came from a client situation where a branch was deployed to production, instead of being merged into master first. I didn't spot that detail right away in the pipeline's history.
For many of us with past source control experience (Subversion, Team Foundation Version Control, Visual Source Safe), there's a subtlety to a Git commit that can trip us up when it comes to build/deployment pipelines. We mistakenly think the pipeline will "get latest."
A Git commit is a snapshot of the entire source tree of the developer's workspace. It's not a record of only that commit's changes. This is why it's critical, before submitting a branch pull request or a commit to mainline (depending on your workflow) that you pull the remote repository's latest code into your local repository.
Imagine two developers, Jasmine and Sabrina. They're going to work on a repo with two files.
At 1pm, they both clone the remote, so both their local repositories exactly match. I'm showing the SHA hashes below.
HEAD aaaa111 <== this is the commit number |_princess.txt bbbb111 |_witch.txt cccc111
Let's be really clear. Git doesn't know about the files. It knows about the hashes it uses to name its copies of the files. So Git's commit tree is:
aaaa111 |_bbbb111 |_cccc111
They each create a separate branch. At 1:30pm, Jasmine changes her file, commits, and creates a pull request. Her commit tree is:
HEAD aaaa222 |_princess.txt bbbb222 |_witch.txt cccc111
When the PR is approved and commit aaaa222 is deployed, those files are deployed.
At 2:00pm, Sabrina changes her file, commits, and creates a PR. Her commit tree is:
HEAD aaaa333 |_princess.txt bbbb111 |_witch.txt cccc222
This is the important part: Sabrina didn't pull from the remote, so her commit tree doesn't include Jasmine's changes.
When the PR is approved and commit aaaa333 is deployed, Git does not get the latest princess.txt nor should it. Git checks out the named commit tree, and that commit has the earlier princess.txt.
What Sabrina needed to do before the PR is:
git checkout main git pull --rebase git checkout myfeature git rebase main git push # OR git push --force <== if the branch was previously pushed
If she does this, her commit tree for the PR will be:
HEAD aaaa444 |_princess.txt bbbb222 |_witch.txt cccc222
Now the PR will deploy the latest files because that's what's in commit aaaa444.