Separating commits by branch

I’m not exactly new to git/github, but I’m not a regular user/contributer and still struggle with the fundamentals. Today, I made a minor typo correction to regexaurus/linkchecker (a fork of linkchecker/linkchecker), on branch typos-regexaurus, committed the change, pushed the commit/branch and opened a PR.

I later checked out a new branch, issueurl-regexaurus, made an edit that should satisfy issue #174 on linkchecker/linkchecker, committed the change, pushed the commit/branch and opened a PR. I was surprised to see that the second PR included/showed the earlier commit as well.

I don’t think this is desirable, and expected only the second/related commit to appear in the second PR.

I would appreciate suggestions on workflow to produce my expected outcome, or help understanding why the actual outcome is normal/preferred.

Thank you!

@regexaurus wrote:

I later checked out a new branch, issueurl-regexaurus, made an edit that should satisfy issue #174 on linkchecker/linkchecker, committed the change, pushed the commit/branch and opened a PR. I was surprised to see that the second PR included/showed the earlier commit as well.

I don’t think this is desirable, and expected only the second/related commit to appear in the second PR.

You are right, that is not desirable. You made a PR to address a single issue and its changes should fix nothing but that issue :smiley:

It sounds to me like you may have created issueurl-regexaurus from typos-regexaurus. You may have been on the page of your fork, with the latter branch selected for viewing, and then created the former from the Branch dropdown. Instead, you should have selected the branch that is even with upstream/parent and created the former from it.

To fix this, I would (personally) clone issueurl-regexaurus to my machine,  git reset --hard  to be even with linkchecker/linkchecker:master, and then git cherry-pick 5a08a55 (the commit meant for the issueurl branch). This procedure overwrites commit history, and that is looked down upon by some, but hey, I doubt the “masters” of linkchecker would merge #176 (with a reverted 1087744) and then accept #175. I think one should keep things clean when presenting work.

I hope that helps! Git it together, won’t ya :wink:

2 Likes

@imasaru

I tried your recommendation:

$ git branch
* issueurl-regexaurus
master
typos-regexaurus

$ git reset --hard

$ git status
On branch issueurl-regexaurus
nothing to commit, working directory clean

$ git cherry-pick 5a08a55
On branch issueurl-regexaurus
You are currently cherry-picking commit 5a08a55.

nothing to commit, working directory clean
The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyway, use:

git commit --allow-empty

Otherwise, please use ‘git reset’

$ git commit --allow-empty
[issueurl-regexaurus 48a0247] Updated support (issues) URL

At this point, CONTRIBUTING.mdwn reflected the typo correction from 1087744. I wasn’t sure this would do what I wanted. Yes, I think you’re correct that I mistakenly created issueurl-regexaurus from typos-regexaurus. I ended up commenting on and closing PR #176 and deleted issueurl-regexaurus, then created a new issueurl-regexaurus from master.

Hey, I’m trying, I’m trying. :smileyvery-happy:

Hmm, it looks like you reset to where the issueurl branch is already at, hence the cherry-pick was empty because the changes were already made.

You should try:  git reset --hard master (because your master branch seems to be even with the parent, so that should do the trick) and then do the cherry-pick. Once you have picked, then force-push to origin (GitHub):  git push origin issueurl-regexaurus -f , which will (f)orcibly push your commit to GitHub to overwrite the current history.