How to avoid tons of commits when debugging Heroku

2020-02-08 09:04发布

While trying to sort out bugs with apps on Heroku, I usually end up with a bunch of Git commits related to the bug fixing process, as I need to commit the updates in order to push to Heroku. Are there any clever ways of cleaning up those commits prior to pushing to the main shared repo for the project?

3条回答
乱世女痞
2楼-- · 2020-02-08 09:27

Create a new branch when you start debugging (git checkout -b debugging or similar), and then make all your commits on there, pushing them to Heroku instead of your master via git push heroku debugging:master.

Then when you've fixed the problem, you can squash your debugging changes into a single commit and merge them back into master:

git checkout master
git merge debugging --squash
git branch -D debugging

There are lots of other ways to go about doing this, it all comes down to which you find the most logical.

查看更多
该账号已被封号
3楼-- · 2020-02-08 09:35

You don't really want to clean up these commits. What you want to do instead is encapsulate them in a merge commit:

  • Check out master -- git checkout master
  • Create a branch for your topic -- git checkout -b my-cool-bugfix
  • Do the work on your branch
  • When ready, git checkout master again, then do a non-fast-forward merge. This is essential: forcing non-fast-forward with the --no-ff option means that a merge commit will always be created. In this case, the command would be git merge --no-ff my-cool-bugfix.
  • You now have one merge commit on master that encapsulates all your branch commits, but retains the commit history so that Git's history analysis tools don't break.
  • When you've tested the fix, git push heroku.
查看更多
够拽才男人
4楼-- · 2020-02-08 09:51

You can do a git rebase -i <commit_before_fixing_commits> and edit / squash / drop the commits and then push to Heroku.

查看更多
登录 后发表回答