-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add guidelines for keeping a clean git history #14
Conversation
Give high-level instructions about fork + feature branch workflow and tips and tricks to keep the git history clean (using rebase).
Love it! From my experience: Request: Let's mention squashing too. (On a similar note, I often do two branches where one is for feature development and the other is for cleaning up the commit history. This is a little more fine-grained than squash-merging a PR via the GitHub PR interface as you still get to choose and combine sub-sub-commits into sub-commits.) |
Thanks for the love, @aaaaalbert! You are right that patch adding might not be the right tool for everyone, but I think it deserves a mention (I use it a lot). Regarding squashing, I suggest that I expand the note about interactive rebasing, briefly mentioning all the possibilities, i.e. rewording commit messages, reordering commits, squashing, ... How does that sound? Personally, I don't like squash merging a PR. I'm in favor of telling PR submitters to keep a clean branch history, so that it is also useful for the overall git history of the project. Btw. for now the target audience of this document are contributors, who submit PRs. Should we also add a note for the maintainers, who merge PRs? Along the lines...
|
I'd love to hear some more opinions. @awwad, @SantiagoTorres does this align with your workflows? @michizhou, do you think this is clear enough for new students? |
Didn't mean to flame Squashing and target audience: You're right, some things should go into a maintainer-flavored doc, not this. |
@awwad provides some more related info in theupdateframework/python-tuf#804 (comment). Is it worth adding some of it to this document? |
@lukpueh said:
In my opinion, it'd be useful to do so. Stuff like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it. See suggested addition and comment on rebasing PRs.
git-history.md
Outdated
the history of your *feature* branch to your hearts content. | ||
|
||
__Resolve conflicts in an open *pull request*__ Once you have submitted a *pull | ||
request* and you are receiving reviews and comments, you should avoid rebasing, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While it's true that you should hesitate before rebasing once the PR is up, there are still a lot of cases where it's still better to rebase than not:
- history cleanup / squashing
- removing unneeded accidental additions
- even IMHO conflict resolution: I think that conflict resolution is better via rebasing than adding additional commits that won't make as much sense in the history once they're merged. (BTW, would be interested if people disagree. I do a lot of rebasing in PRs.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I totally agree with you on above items. There are two reasons why I think rebasing on PR's that are actively being reviewed should be avoided:
- AFAIK review code comments are bound to commit ids, hence break on rebase. I do have the feeling that GitHub made some enhancements in that regard, but I haven't checked.
- If I write a comment on someone's
Added foo
commit, that says "please modify bar", then it's easier for me to re-review, if the person pushes aModified bar in foo
commit, instead of e.g. silently modifying bar and force pushing it toAdded foo
.
However, once all the "please modify bar" comments are addressed and green-lighted by the reviewer, I think the contributor can/should squash the review-addressing commits, and use rebase to fix conflicts or clean up the history in general.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK review code comments are bound to commit ids, hence break on rebase.
Fancy a quick test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per the insights from my quick and fancy (ah ... dirty) GitHub/rebase test below, I would conclude that GitHub does a pretty good job in tracking rebases. So you can probably disregard my first concern above. However, the second one is still relevant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally advice that in general we should keep git usage guidelines disconnected from github guidelines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It sounds like we're roughly in the same place, then. I agree that generally a review-motivated/requested code fix should be provided in an additional commit.
git-history.md
Outdated
forward, because some other work was merged into the *main* branch. Check | ||
regularily, especially before you submit a *pull request*, if the | ||
base of your *feature* branch has moved forward. If it has, use `git rebase` | ||
to update the base and fix conflicts as they occur. (`git fetch --all` and `git rebase <upstream>/<main branch>` instead of `git pull`). [Here's](https://github.com/theupdateframework/tuf/pull/804#issuecomment-440017361) an example in practice. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing a review comment on a line that will change and links to lines that change and lines that don't change after a rebase and force push.
- https://github.com/secure-systems-lab/lab-guidelines/pull/14/files#diff-b4039e218e46891be5b013b445f12c47R37
- https://github.com/secure-systems-lab/lab-guidelines/blame/84b06d128cff13ecadc017793d7f41bb8001dcf8/git-history.md#L37
- https://github.com/secure-systems-lab/lab-guidelines/blob/84b06d128cff13ecadc017793d7f41bb8001dcf8/git-history.md
- https://github.com/secure-systems-lab/lab-guidelines/pull/14/files#diff-b4039e218e46891be5b013b445f12c47R36
- https://github.com/secure-systems-lab/lab-guidelines/blame/84b06d128cff13ecadc017793d7f41bb8001dcf8/git-history.md#L36
While you are working on your *feature* branch the *main* branch might move | ||
forward, because some other work was merged into the *main* branch. Check | ||
regularily, especially before you submit a *pull request*, if the | ||
base of your *feature* branch has moved forward. If it has, use `git rebase` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing a review comment on a line that will not change and links to lines that change and lines that don't change after a rebase and force push.
- https://github.com/secure-systems-lab/lab-guidelines/pull/14/files#diff-b4039e218e46891be5b013b445f12c47R37
- https://github.com/secure-systems-lab/lab-guidelines/blame/84b06d128cff13ecadc017793d7f41bb8001dcf8/git-history.md#L37
- https://github.com/secure-systems-lab/lab-guidelines/blob/84b06d128cff13ecadc017793d7f41bb8001dcf8/git-history.md
- https://github.com/secure-systems-lab/lab-guidelines/pull/14/files#diff-b4039e218e46891be5b013b445f12c47R36
- https://github.com/secure-systems-lab/lab-guidelines/blame/84b06d128cff13ecadc017793d7f41bb8001dcf8/git-history.md#L36
Add example that shows how to fix conflicts using git rebase. NOTE: Amending this commit to test how GitHub fares with rebases.
84b06d1
to
d3e6463
Compare
GitHub and rebase test insights (see #14 (comment))):
|
Just something that I realized recently when reviewing some PRs for unrelated personal repositories is that it's a lot easier if we have PR authors avoid force-pushing, rebasing, and other destructive git history operations until it comes time to merge. Otherwise, the squashed commit history makes it hard for the reviewers to tell if the PR author actually addressed their review comments as well as to figure out any other changes they might have made. I think it would be helpful to include this guideline somewhere in the guide. |
I should clarify that in my previous comment I am referring to self-rebasing such as |
Emphasize on avoiding rebasing on open PRs, to make reviews easier, but allowing rebasing to fix conflicts.
d7989f9
to
f26e6fd
Compare
I made some minor modifications in the "rebasing on an open PR" paragraph, to integrate our recent discussions, and will merge now. |
This is a first stab at creating a guideline document for keeping a clean git history in our lab code projects. At the moment the document purely reflects my personal opinion, albeit based on my experience in this lab. I'd love to hear other thoughts and ideas to make this better.
And here are some additional thoughts that I'd like to throw into the discussion: