duebstep
duebstep

Reputation: 197

Git - Pull request with current changes but not previous commits

I created a branch from an origin, and made changes on that branch. I made several commits to show a friend what I was doing, but I don't want these commits to show up on the origin when I make a pull request.

How can I make it so only one commit will show up on the pull request.

What I was thinking about doing was creating another branch, and resetting my previous branch to head.... But I don't really know what to do.

Thanks in advance!

Upvotes: 1

Views: 80

Answers (2)

Thomas Stringer
Thomas Stringer

Reputation: 5862

What you're looking to do is to squash the commits on the branch.

This can be done by (in the new branch that you want to modify) type the following:

$ git rebase -i <your_starting_commit_SHA>

And then you'll be able to either pick or squash the commits (or reword a commit so that it matches a more appropriate commit message after the squashing).

When you do this interactive rebase, you will be confronted with the following:

pick <commit1_SHA> <commit1_message>
pick <commit2_SHA> <commit2_message>
pick <commit3_SHA> <commit3_message>
pick <commit4_SHA> <commit4_message>
# ... so on and so forth

If you want to squash all of your commits into your original one, then you would keep pick for the first commit, and then change the remaining picks to squash. Git would then squash commit2, commit3, and commit4, into commit1 therefore giving you your clean commit history before your pull request.

The end result here would be a single commit with your reworded commit message, instead of the original four commits (used for illustration purposes, of course).

Upvotes: 1

sestus
sestus

Reputation: 1927

Here is what I would do:

Suppose that your cloned branched from origin is called A. I would clone the origin again into a new branch called B. Then I would merge the A branch into the B branch, using the --squash flag (while on branch B: git merge --squash A), so all of your commits in Branch A, would go to Branch B as one. Then you can issue a pull request from your B branch

Upvotes: 0

Related Questions