Excluding a commit from a PR that is already in a PR

create pull request for specific commit bitbucket
remove commit from pull request
github cherry-pick pull request
github pull request exclude commit
git exclude file from pull request
git revert
git rebase
git revert commit

I have an open PR with a commit I did

I made another commit and want to create another PR with just these changes.. however the previous commit is in there.

I realize branches would resolve this, yet, here we are. Do I just need to wait for the PR to be merged?

I have an open PR with a commit I did

At that point your repository looked something like this.

A - B [master]
      C [pr1]

Commit B is where master is at. And you have a branch called pr1 with a commit C on it.

I made another commit and want to create another PR with just these changes.. however the previous commit is in there.

What probably happened is you branched from pr1 rather than master resulting in this.

A - B [master]
      C [pr1]
        D [pr2]

When you make a PR for pr2 by default the base branch is master so it shows C and D in the PR.

If the work in D does not depend on C what you want is for pr2 and commit D to be branched from master.

      D [pr2]
A - B [master]
      C [pr1]

You can fix this by rebasing pr2 onto master.

git rebase --onto master pr1 pr2

That says to replay the commits starting at (but not including) pr1 to (and including) pr2 onto master. Then you can push pr2 and create an independent PR.

If the work in D does depend on C then it's best to leave pr2 on top of pr1. Create a PR for pr2 with the base being pr1 instead of master. Once pr1 is reviewed and accepted, then pr2 can be reviewed and accepted.

Be sure to make a note in the PR description that pr2 is stacked on top of pr1 so the reviewer doesn't miss it. "This depends on #123" where #123 is the ID of pr1's PR.

How to remove commits from a pull request, git checkout my-pull-request-branch. git rebase Now you'll have removed the commit from your remote, but will still have the changes locally. TRAVIS_COMMIT_RANGE uses triple dots, which includes commits that are in the base branch that are not in the PR. For example, if a commit is pushed to master with an incorrect summary, then every PR created before that commit will include the unrelated commit, causing the PR to fail the summary check.

Just create a new branch from whatever point you want to start and cherry-pick the other branch. That will apply the changes involved on the last revision of the other branch and no other changes (assuming it's the last revision from that branch).

How to exclude old commits in new pull request?, To exclude commits from your pull request branch you would perform an Unfortunately you already pushed your changes on your forked  Rebase essentially rolls up all the commits on your branch and then moves the branch to the tip of master and then replays all your commits. This means that it looks as if you created the branch from the tip of master.

An easy way to do this, is by using interactive rebase.

If you run git log --oneline on your branch, you should see something that looks like this:

ccccccc (HEAD -> your-branch-name) Your (good) commit you want to keep
bbbbbbb bbbbbbb Your (bad) commit you want to remove from history
aaaaaaa (master) Commit from you or someone else

You say you want to remove bbbbbbb replacing it with ccccccc.

Because ccccccc contains changes since bbbbbbb, removing it would cause lots of conflicts, as you'd have to merge ccccccc into aaaaaaa.

The git way to do it, is to squash ccccccc into bbbbbbb, creating a new commit ddddddd. And for that, you'd do the following steps:

1. Run git rebase -i aaaaaaa to open the interactive rebase, starting from the commit immediatelly before the one you want to remove

This will open your configured text editor with something that looks like this:

pick bbbbbbb Your (bad) commit you want to remove from history
pick ccccccc Your (good) commit you want to keep

# Rebase aaaaaaa..f5a9551 onto aaaaaaa (2 commands)
# Commands:
# p, pick <commit> = use commit
# r, reword <commit> = use commit, but edit the commit message
# e, edit <commit> = use commit, but stop for amending
# s, squash <commit> = use commit, but meld into previous commit
# f, fixup <commit> = like "squash", but discard this commit's log message
# x, exec <command> = run command (the rest of the line) using shell
# d, drop <commit> = remove commit
# l, label <label> = label current HEAD with a name
# t, reset <label> = reset HEAD to a label
# m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
# .       create a merge commit using the original merge commit's
# .       message (or the oneline, if no original merge commit was
# .       specified). Use -c <commit> to reword the commit message.
# These lines can be re-ordered; they are executed from top to bottom.
# If you remove a line here THAT COMMIT WILL BE LOST.
#   However, if you remove everything, the rebase will be aborted.
# Note that empty commits are commented out

The list shows what the interactive rebase will do: From aaaaaaa, pick bbbbbbb, then pick ccccccc

2. As I said above, you want to squash ccccccc into bbbbbbb, so replace the word pick before ccccccc by squash:

pick bbbbbbb Your (bad) commit you want to remove from history
squash ccccccc Your (good) commit you want to keep

3. Save the file, and close the text editor.

4. Another text editor will open, to ask you to specify the message of the new commit being created, with the combination of ccccccc and bbbbbbb - which I'm calling ddddddd for the sake of this example:

# This is a combination of 2 commits.
# This is the 1st commit message:

Your (bad) commit you want to remove from history

# This is the commit message #2:

Your (good) commit you want to keep

Here you probably want to delete everything except the last line, which has the message of your latest commit, but feel free to customize the message however you like.

5. Save the file, and close the text editor.

The rebase is done, and your history should look like this:

ddddddd (HEAD -> your-branch-name) Your (good) commit you want to keep
aaaaaaa (master) Commit from you or someone else

6. Now, all you have to do is to send to push the branch back to your origin (e.g. GitHub/BitBucket/GitLab), etc. in order to update your pull-request.

For that, you'll have to do a push --force, so that your remote branch is replaced by this new one.

git push origin your-branch-name --force

Of course, you always have the option of closing the previous pull-request and opening a new one instead (with a different branch name).

How do we "reject" a commit on a Pull Request? · Issue #12 , Funny there is no "Merge at this point, ignore later" button. Merging the pull request will merge all commits in that branch to the base branch. In our company the system is set to perform the commitment as soon as the PR has been created. For example: Transaction FMB_PL01 shows something like that. Original Budget $1000. Purchase Req. $600. Remain Budget $400. Once created the PR, Ours PO are created with reference a contract which has a PR or the PO's are created directly against a PR.

How to merge only specific commits from a pull request with git , Now I had a pull request with one good commit and one bad commit. A screenshot of two commits, one good and one bad. I asked the author,  If you want leave file in your branch, but not to merge it to main branch, you can delete it in one commit, then add again in another. Git allows you manually accept certain commits using git-cherry-pick. You can accept each commit except that in which you have added this file again.

3. Lifecycle of a Pull Request, If an issue is trivial (e.g. typo fixes), or if an issue already exists, you can skip this step. If a core developer reviewing your PR pushed one or more commits to your Do not fix more than one issue in the same commit (except, of course, if one  "Cherry pick" the commits you want into this branch. Go to either the git log or the GitHub UI and grab the unique commit hashes for each of the commits that you want, and then run this command: git cherry-pick super-long-hash-here. That will pull just this commit into your current branch. Push up this branch like normal. git push origin master.

How To Rebase and Update a Pull Request, Once you submit a pull request, the process of contributing to a project can Now if you know the number of commits you've made on the branch that you want to Now, for each line of the file except for the first line, you should replace the  This introduces a new commit and GitHub doesn't recognize that this squashed commit is the same as the ones already in master (but with different hashes). Git handles it properly but you see all the changes again in GitHub, making it annoying to review.

  • Why not just revert it?
  • What is the point of keeping in a private branch a revision you actually don't want in history? Just get the history fixed, no need to revert. #imho