How to Exclude Commits on a Merge Based on Conditions in Git

code-reviewsgitproductivityteamwork

My eyes are destroyed. I am using a screen reader.

We are using git as our version control system on our project. We host our own server and use ssh to access it. We put each module under separate branches, then merge them all to a branch called dev for testing. Then when we determined that everything is stable, we merge dev to master.

Lately I am finding we are using remote branches in an unusual way. For example, suppose my partner found a bug he couldn't fix. Tipically I would ask him to read the code and suggest some fixes. If that is imposible (e.g. he does not know what to read or code is too long), we do the following.

  • He commits the file containing the bug and pushes it to the remote branch.
  • I would then pull his last commit and read his code and try to understand the bug.
  • This repeats over and over until the bug is fixed. Sometimes I would ask him to push related files to the current file (E.G. maybe the problem is how json data is formatted so I have to read the file that submits the json object to the current file.)

For me, Git made this process very easy. I now have a way to personally inspect someones code without annoying people to reread a large portion of their code to me if I want something clarified. However, I believe we are using commits in a very bad way. I couldn't easily delete those commits in the local branch because they are already pushed into the remote branch.

My first solution is: when merging my module to dev, I would exclude all commits that are not real commits using some identifier or some range. The problem is the commits are scattered depending on when the bug occurred and what time. Rebasing them could be very time consuming and unproductive to the other developers on the team. I don't know how to achieve what I want.

What should I do?

Best Answer

Keep the commits. They are REAL commits.

When viewing the history, only look at the branch merge commits. These contain all the changes in one commit.

git log --merges

Check out the other advanced git log features which might help with a screen reader.

https://www.atlassian.com/git/tutorials/git-log

Related Topic