I used Perforce most of my career and am still getting used to git, so I think I'm either not realizing that my scenario doesn't match the scenarios in the following posts, or I'm missing some implicit steps that are obvious to regular git users but not to me.
It seemed whenever I cherry-picked, I ended up with a branch with no changes (which makes sense though, since they're already committed to master, right?—then how do I create this "topic branch" I see being mentioned?) And now I have run several commands I don't fully understand (e.g. git remote add ...
) and also possibly interchanging the original author's repo versus my forked repo in them, so it's becoming hard to tell whether things aren't working because I've messed my environment up.
@Omer's answer worked great. I then did a
git reset --hard HEAD
to clean up. The original author merged the PR, and I sync'ed to it:
git remote add upstream git://github.com/<author>/<repo>.git
git pull upstream master
In your repository, use git log
to figure out the commit hash of the latest commit that does not belong to you (the commit that was latest in master when you forked). From now on I'll refer to this hash as abcd
.
Checkout and create a new branch on YOUR latest commit (NOT abcd), by doing:
git checkout -b andrew_pr
Now perform a mixed reset so the andrew_pr
branch will branch off of abcd
, but you'll still have all your previously committed changes as local changes:
# Remember to replace "abcd" with the commit hash from the beginning!
git reset --mixed abcd # <---- Replace abcd
Now that all your changes are as simple local changes, you can perform an interactive git add using:
git add -p
This will guide you with a prompt through each of your changes, and you can knock some changes off and keep some other changes. Of-course, you'll want to keep all the changes you wish to see in the PR.
Once you're done, commit
git commit -m "Andrew's changes"
And push
git push --set-upstream origin andrew_pr
The push logs should give you a convenient link to create a pull request. Follow that link and submit your PR.