3

I have a Git branch develop, and on that branch, there are a number of commits that are just debugging statements and shouldn't be in production. Meanwhile, I want to create a pull request from the develop branch onto our feature branch, but I don't want to include the debugging commits.

It seems like my two options for doing this are to (1) create a develop-copy branch, drop the appropriate commits from that branch, and make a PR from develop-copy or (2) drop the appropriate commits from develop, make the PR, then cherry-pick the commits back into develop. Both of these are kind of a pain.

Is there a way to just push a certain set of commits or to have two branches that are copies of each other except for these commits? Thanks.

jay
  • 1,524
  • 4
  • 25
  • 45
  • If you want to push only specific commit, you can look at this answer http://stackoverflow.com/questions/3230074/git-pushing-specific-commit – afonte Feb 24 '17 at 20:05
  • I guess that's an option, squashing everything that _isn't_ a debugging commit and then pushing that one commit. – jay Feb 24 '17 at 20:53

3 Answers3

0

Is there a way to just push a certain set of commits or to have two branches that are copies of each other except for these commits?

No. You can only push references to commits, and commits are defined by their contents and their parents.

Honestly, instead of juggling debug statements in separate commits, you should probably figure out how to leave them in but optimize them out for production.

dahlbyk
  • 75,175
  • 8
  • 100
  • 122
  • Agreed, but my teammates are complaining that the debugging statements create noise in code reviews. (Which, to be fair, they do.) – jay Feb 24 '17 at 20:50
  • In that case, I would make sure your debug statements are in their own commits and just drop them with a `rebase --interactive` before you ask for review. That being said, consider why you need so many debug statements as to distract from code review. I've generally found that good unit test coverage yields a better understanding of code than debug statements, though YMMV. – dahlbyk Feb 24 '17 at 22:05
0

Another option, if you are the only one working on that branch, is to rebase it interactively.

git checkout develop
git rebase -i
# reorder commits
git push --force

You can then reorder commits, putting the debug ones in last

Then you can make a new branch starting from the last non-debug commit, push it and make your PR from that new branch.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

Just do an interactive rebase, git rebase master -i, and either remove or fixup the random commits you want out of the pull request.

pick fdfb01e Real commit
# pick a382ce3 Debugging some random issue
# pick 02ff8dc Remove debugging code
fixup ddf5e91 Add missing semicolon
pick 73c7e11 Real commit
jaredready
  • 2,398
  • 4
  • 23
  • 50