Skip to content

Add docs on updating PRs using git #10997

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

Closed
wants to merge 1 commit into from

Conversation

timhoffm
Copy link
Member

@timhoffm timhoffm commented Apr 8, 2018

PR Summary

This PR adds documentation on how to update PRs using git by amending or squashing.

This is in the context of #8503.

@ImportanceOfBeingErnest
Copy link
Member

👍 This exactly what I need. Just a question: Often people review certain lines of code. How are those treated? Will the review then point to a nonexisting line after ammending?

Often, you'll want to update your contribution based on the feedback in the
pull request. While it's possible to simply push additional commits to your
feature branch, this will clutter the history. Not every step in the
development of a feature is worth to be recorded. In contrast, a clean
Copy link
Member

@phobson phobson Apr 8, 2018

Choose a reason for hiding this comment

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

perhaps "not every step...is worth recording"

pull request. While it's possible to simply push additional commits to your
feature branch, this will clutter the history. Not every step in the
development of a feature is worth to be recorded. In contrast, a clean
history with one or a few thematically separted commits helps to keep it
Copy link
Member

Choose a reason for hiding this comment

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

separated


Both techniques rewrite the history of your feature branch. While generally
one has to be careful with rewriting the history, this is intended and
perfectly fine for updates to your feature branch.
Copy link
Member

Choose a reason for hiding this comment

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

perhaps: "perfectly fine for commits that are currently on your feature branch only".

a point that should be clear is that commits already in master shouldn't be touched.

On your feature branch::

# make your updates
git commit --all --amend --no-edit
Copy link
Member

@phobson phobson Apr 8, 2018

Choose a reason for hiding this comment

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

Non-blocker: I'm a little nervous about recommending --all. I'd prefer to instruct people unfamiliar with git to add each of the files rather that possibly adding a bunch of unrelated files.

Copy link
Member

Choose a reason for hiding this comment

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

Yes definitely agree. For better or worse I have a bunch of test files in my local dev repository and if I used -all I’d be in a lot of trouble.


git reset --soft HEAD~3
git commit
git push --force
Copy link
Member

@phobson phobson Apr 8, 2018

Choose a reason for hiding this comment

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

does this achieve the same thing as:

git checkout feature-branch
git rebase -i HEAD~8 # opens text editor, check your gitconfig
# use the fixup option on all but the first line
# save and exit text editor (for vim that's ":wq")
git push origin feature-branch --force

Copy link
Member

Choose a reason for hiding this comment

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

Yeah it does. But I think it requires one fewer editor opens. I somewhat prefer the rebase option.

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 think so, but you're never quite sure with git. I took this from https://stackoverflow.com/a/5201642/2726279

Copy link
Member Author

@timhoffm timhoffm Apr 8, 2018

Choose a reason for hiding this comment

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

In my experience rebasing is more difficult to understand than soft reset. That's why I chose this approach. I still feel like I cannot explain rebasing reasonably simple.

Any help with rebase and the "Rewriting commit history" section would be welcome.

@phobson
Copy link
Member

phobson commented Apr 8, 2018

@ImportanceOfBeingErnest when an individually reviewed line changes, the GitHub UI collapses the comment. You can click on a button labeled "show outdated comment" to see the history. Your PR from the pie docs has this: #10953 (review)

@timhoffm
Copy link
Member Author

timhoffm commented Apr 8, 2018

You can see the outdated comment and the few lines of code segment. However, naturally the "View Changes" button leads nowhere as there is simply no commit associated anymore. This is inherent. We wanted to throw away the preliminary commits.

@timhoffm timhoffm force-pushed the doc-git-update-pr branch from f8dfcef to 75215c4 Compare April 8, 2018 19:05
@ImportanceOfBeingErnest
Copy link
Member

Ok, so this is in anyway desireable to do.

There is a section down below at that page called "Rewriting commit history", should that not somehow unified with the new changes?


A further note. I think the problems I had with previous PRs trying to squash was that there were other commits from other people in between those I wanted to merge.

So when I did

git rebase -i HEAD~4

the commits shown in the editor were not just my last commits from my branch, but simply the last 4 commits to the matplotlib. E.g.

pick xxxxxxxxx myupdate 1
pick yyyyyyyyy someone else's update
pick xyyxyxyxy myupdate 2
pick zzzzzzzzz another person's update

So it wasn't clear what to do then.

The explanation in the "Rewriting commit history" has the drawback that it isn't clear which of the mentionned commits would be mine. Also there is the word "last", for which I wasn't sure if it is meant temporarily (newest) or spacially (bottom-most?).

Also git log --oneline continuously lets my git become unresponsive. I did look the website's numbers to find out instead. Maybe that is a known issue? But it makes it even harder to determine which commit to specify in

git rebase -i yxzxyzxy

Concerning ammend, is this still an option if you already have several commits (due to forgetting to ammend previously or due to not knowing about the existance of this option)?

@jklymak
Copy link
Member

jklymak commented Apr 8, 2018

@ImportanceOfBeingEarnest that’s almost certainly because you did a merge commit before you attempted rebasing. I’ve done that by accident a few times and if that happens you better hope you have a backup. That eventuality would ideally be covered here as well.

I agree that this should be homogenized with the rewriting history.

Btw I’m not sure we get to edit any of this. I think it gets pulled from the gitwash repository.

@timhoffm
Copy link
Member Author

timhoffm commented Apr 8, 2018

If you've accidentially merged, you can still reset --hard to your branch before the merge commit.

The "Rewriting commit history" section is also part of development_workflow.rst. It's editable in principle, but I don't feel comfortable with the topic.

@ImportanceOfBeingErnest Concerning amend when you already have multiple commits. You an change single ones but the number of commits will stay. How to amend the last one is explained above. To amend an earlier commit you have to edit and commit-amend as part of a (interactive) rebase.

@jklymak
Copy link
Member

jklymak commented Apr 9, 2018

That reset --soft is really useful. Definitely get that in.

But again, do we actually get to edit this, or is it just copied from https://github.com/matthew-brett/gitwash/tree/master/gitwash ? I think the changes need to be proposed there, but I'm fuzzy on whether that is really the case.

@tacaswell
Copy link
Member

This should be opened up against upstream gitwash or your changes will at somepoint be blown away and you will be sad.

@jklymak
Copy link
Member

jklymak commented Apr 28, 2018

@timhoffm I'm closing this as this is the wrong repository for this. But I think the actual work is great!

@jklymak jklymak closed this Apr 28, 2018
@timhoffm timhoffm deleted the doc-git-update-pr branch June 10, 2022 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants