Git - Commit with no changes contains bug

git push
git reset
git revert commit
changes not staged for commit:
git add
git commit with message
git commit and push
git commit command with message

Consider this git history. If I checkout the second highlighted commit (or any commits above it / newer), then it contains a bug that I can see on screen (specifics of bug not too relevant).

If I checkout the third commit (or any commits below it / older), then I no longer see the bug on screen.

As you can see though, the second commit containts 0 changed files with 0 additions and 0 delations.

How then does switching between these two commits introduce or remove the bug that I'm trying to fix!? I can't tell which files are being changed between the two commits?


Update

The above image isn't strictly true, the actual situation is below. I didn't realise this could happen in GIT, if someone could explain how NO BUG could get reintroduced on the "Ensure we always return an integer" commit that would be great!

History is rarely a straight line

In your updated graph image, you have newer commits towards the top and older commits towards the bottom. Everything has been forced into a nice neat straight line. But this is a warped view of reality, in the same way that every view is warped. (We can introduce Einstein and relativity if needed, to prove this, but let's just take it as a given that we like to view things from where we sit / stand now, as opposed to where things were back when they were however they were and we didn't have today's perspective. Tomorrow or next year we'll have yet another perspective!)

Let's redraw this history a different way to make things clearer. We'll put older work on the left and newer work on the right and draw it in parallel, like this:

...--o--o---o
             \
              X--X--X   <-- master
             /
...--o---X--X   <-- feature/buggy
         ^
         |
  bug introduced

where X represents a commit with a bug. Note that the first buggy commit, on the bottom row, came after one of the good commits shown on the top row, then the second buggy commit came at the same time as (or even slightly before) the last good commit on the top row. The bug was obviously first introduced at the point I've marked.

Now, if we draw this linearized vertically with newer commits at the top, we get:

.
.
.
X   (still has bug introduced by merge)
X   (bug first introduced by merge)
o   (commit from the top row, not broken)
X   (bug in feature/buggy - commit from the bottom row)
X   (bug in feature/buggy)
o   (commit from the top row, not broken)
.
.
.

In the linearized view, the buggy commits are separated by good commits. In a "correct" (or at least less-distorted) view that looks at history one "leg" at a time, the buggy commits are all in a row.

The actual view you show, in the updated graphic, has a commit whose log message says Merge remote-tracking branch 'AWS/... (this gets cut off), but which is not a merge commit (a commit with two or more parents). This is the kind of merge made by git merge --squash, or—on some web interfaces—clicking a button labeled something like "squash and merge". These commits are made by using Git's merge machinery but do not record correct history.1 So in this case, the only way I know this is from harsh experience: I've seen this exact kind of problem before. The graphs I've drawn here show how things would look if the merge had been a regular merge, instead of a squash merge.

None of this is all that critical here, but someone in your organization should probably take some time and learn how Git works at a fine-grained level, to make finding and fixing bugs easier in the future.


1This is often intentional: the idea is to lie about the history to make future investigation easier, even in in fact it makes future investigation harder. How well this "squash" feature works depends on the skill and knowledge of those who use it. Anyone using it blindly is using it wrong, in the same sense that anyone who uses power tools without learning how to use them safely is using them wrong, even if they're accidentally using them right. 😀

git-commit Documentation, prashantakerkar opened this issue on Mar 29, 2016 � 34 comments git push has concluded that there's nothing to push there, how are you judging that there� This command uses a binary search algorithm to find which commit in your project’s history introduced a bug. You use it by first telling it a "bad" commit that is known to contain the bug, and a "good" commit that is known to be before the bug was introduced. Then git bisect picks a commit between those two endpoints and asks you whether the

I will comment on what the following text actually means:

Showing 0 changed files with 0 additions and 0 deletions

This just means that the bottom (second) commit doesn't have any changes versus the commit which came before it. So, if checking out this commit resolves the bug, it doesn't necessarily mean that the commit is what introduced the changes to fix it. Rather, some earlier commit is responsible. For a diagram, consider:

A -- B -- C

The bug was introduced in commit C, but was not present in commit A. Since commit B was effectively a no-op, it too also does not have the bug present.

Push command successful but no changes reflected on , Whether you added the wrong file, committed directly to master, or some Now, without any further ado, here's how we can fix six of the most common After a good few hours of coding, it's easy for a spelling error to sneak into your commit messages. I committed all those changes to the master branch. The man page (man git-rerere) has more information on further use cases and commands (git rerere status, git rerere diff, etc). 8. Find the commit that broke something after a merge Tracking down the commit that introduced a bug after a big merge can be quite time consuming. Luckily git offers a great binary search facility in the form of git

Have you heard of git bisect?

This command when executed and followed, will pinpoint the exact one commit that introduced the bug.

Briefly, you start by executing the command and giving it a "starting point" (a commit SHA) that you know did NOT have the bug, then you give it an "ending point" (also a commit SHA) that you know DID have the bug, then git will do divide-&-conquer sort of process and will checkout versions for you, on each checkout, you test and see if the bug is there or not and you tell it to git (bad vs good), and git will continue the search based on your input. Finally, it will display the commit that introduced the bug.

Worth a try and is easy (and super fun) to do.

Git happens! 6 Common Git mistakes and how to fix them, Git documentation has this chicken and egg problem where you can't search for how to get yourself out of a mess, unless git commit --amend # follow prompts to change the commit message Oh shit, I tried to run a diff but nothing happened?! If you committed a bug, you can undo the commit all in one go with revert . You use it by first telling it a "bad" commit that is known to contain the bug, and a "good" commit that is known to be before the bug was introduced. Then git bisect picks a commit between those two endpoints and asks you whether the selected commit is "good" or "bad". It continues narrowing down the range until it finds the exact commit that

Oh Shit, Git!?!, git add . git commit -m "fix bug" git push. You repeat this process a few times, You check back through your commits, and you no longer remember the The body contains the meat of your message and is where you can go� Review and commit the changes?" Can't reproduce. There is a big recurring bug that has emerged since 2.0: under some circumstances (I think during rebase, but am not sure), the working directory gets filled with changed files , and the workaround is to reset the branch .

Stop Writing Bad Commit Messages. Start following best practices , The commit contains the following structural elements, to communicate intent to the consumers fix: a commit of the type fix patches a bug in your codebase (this correlates with A BREAKING CHANGE can be part of commits of any type. No! If you use a squash based workflow on Git lead maintainers can clean up the � git cherry-pick is a powerful command that enables arbitrary Git commits to be picked by reference and appended to the current working HEAD. Cherry picking is the act of picking a commit from a branch and applying it to another. git cherry-pick can be useful for undoing changes. For example, say a commit is accidently made to the wrong branch.

Conventional Commits, The change is not sent to a central repository, though. This stages those changes for commit, calling git commit closes the loop. with Git, you probably tried those same aliases and been given an error that it was not a git command. You need to find out what has changed in your working tree and how it's changed. git commit -m “[DOC] my documentation change” Based on the annotations above, it’s quite easy to generate a simple list that contains for example all features, or all features and bug fixes etc.

Comments
  • Thank you for your answer, I'm sure it makes sense to someone who knows the concept, but I'll explain why I'm still confused. I've updated the picture for clarity. The bug is introduced at point of checkout out the Merge commit (and any more recent) so I don't understand how an earlier commit could be responsible, as checkout out an earlier commit doesn't contain the bug? In other words, which commit contains the bug!?
  • This just looks like a merge commit introduced a bug, nothing special happening. Most likely, the earlier commit you are referencing does not have the bug, implying that the incoming branch is the culprit.
  • So none of these 4 commits contain the bug!?
  • No, the commit which you have highlighted, and presumably onward, does contain the bug. But, my guess is that this bug was introduced by the branch which you merged into your branch shown above.
  • For future reference, git bisect will help you find the first bad commit similarly to what you've done here manually, but is smart about merge commits and will track the bug across merges into other branches.