Skip to content
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

Merged
merged 5 commits into from
Nov 30, 2018

Conversation

lukpueh
Copy link
Member

@lukpueh lukpueh commented Nov 14, 2018

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:

  • Can we make this more concise?
  • Should we add command line examples?
  • Can we better leverage existing guidelines and howtos?

Give high-level instructions about fork + feature branch workflow
and tips and tricks to keep the git history clean (using rebase).
@aaaaalbert
Copy link
Contributor

Love it!

From my experience: git add -p for feature separation can be difficult because it's easy to overlook stuff, and you'd have to test the committed parts separately. So technically things are separated, but they'll not always work as intended.

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.)

@lukpueh
Copy link
Member Author

lukpueh commented Nov 16, 2018

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...

  • make sure your contributors follow this guideline
  • merge with --no-ff (default when using GitHub UI)

@lukpueh
Copy link
Member Author

lukpueh commented Nov 16, 2018

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?

@aaaaalbert
Copy link
Contributor

Didn't mean to flame add -p, it's a great tool and should definitely be mentioned.

Squashing and target audience: You're right, some things should go into a maintainer-flavored doc, not this.

@lukpueh
Copy link
Member Author

lukpueh commented Nov 20, 2018

@awwad provides some more related info in theupdateframework/python-tuf#804 (comment). Is it worth adding some of it to this document?

@alyptik
Copy link

alyptik commented Nov 20, 2018

@lukpueh said:

@awwad provides some more related info in theupdateframework/tuf#804 (comment). Is it worth adding some of it to this document?

In my opinion, it'd be useful to do so. Stuff like git rebase is a bit weird to get the hang of if you haven't used it much, and @awwad explained the process quite well. Once condensed a bit it'll fit in perfectly.

Copy link
Contributor

@awwad awwad left a 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,
Copy link
Contributor

@awwad awwad Nov 20, 2018

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.)

Copy link
Member Author

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 a Modified bar in foo commit, instead of e.g. silently modifying bar and force pushing it to Added 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.

Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do

Copy link
Member Author

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.

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.

Copy link
Contributor

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 Show resolved Hide resolved
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.
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`
Add example that shows how to fix conflicts using git rebase.

NOTE: Amending this commit to test how GitHub fares with rebases.
@lukpueh
Copy link
Member Author

lukpueh commented Nov 21, 2018

GitHub and rebase test insights (see #14 (comment))):

@alyptik
Copy link

alyptik commented Nov 27, 2018

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.

@alyptik
Copy link

alyptik commented Nov 27, 2018

I should clarify that in my previous comment I am referring to self-rebasing such as git rebase -i @~5 to squash/reorder/drop commits. Rebasing on the parent branch because of new commits shouldn't cause any issues.

Emphasize on avoiding rebasing on open PRs, to make reviews easier,
but allowing rebasing to fix conflicts.
@lukpueh
Copy link
Member Author

lukpueh commented Nov 30, 2018

I made some minor modifications in the "rebasing on an open PR" paragraph, to integrate our recent discussions, and will merge now.

@lukpueh lukpueh merged commit 211ab06 into secure-systems-lab:master Nov 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants