Reputation:
I have a pull request on a repository. The commits are still unmerged. Now, I want to make another pull request, totally independent from the previous one. When I create a new branch and make the new commits, all of the unmerged commits are also alongside with the new ones!
I want to create a new pull request without the unmerged commits. Please help me on how should I do that as I'm new to git :)
Upvotes: 3
Views: 1845
Reputation: 9598
You probably created your branch not from master but from your recent feature branch. To branch from your master you must first checkout the master.
This is what I would do.
(1) fork on github (2) Clone origin to your computer (2) Add your fork as a remote. (3) Push new branches to your fork. (4) Make pull requests from your fork to the origin master
Look up github workflow as an example of a well tested approach.
Go back to your master
git checkout master
Often it is a good idea to sync it to the origin
git pull origin master
Make sure that everything is like expected
git log
git status
Now create your branch
git checkout -b new_branch
Now look up the commits in your original branch
git log old_branch_with_to_many_commits
All commits have a hash. You can use those numbers to cherry-pick single commits into your new_branch. So copy the hash of first commit you want to keep into your clipboard.
Now use git cherry-pick to get single commits into your new_branch one by one
git cherry-pick a_commit_hash
...
git cherry-pick next_commit_hash
Now you might want to clean the commits from your old branch.
git checkout old_branch_with_to_many_commits
Lookup the hash of the last commit you want to keep
git log
Copy the hash to reset the branch
git reset --hard hash_of_the_last_commit_you_want_to_keep
Upvotes: 0
Reputation: 191
Create Satsh which will temporary store you commits in some storage
git stash
Then create a new brnach
git checkout -b "new branch name".
Then get all that commits in the new branch by poping the stash
git stash pop
all commit which is in old branch will be saved here.
or else If you want to commit and all changes are also committed to new branch so simply just commit all changes in that branch and make a new branch.
git checkout -b "new branch"
as you created new branch from previous branch all changes are taken in new branch
Upvotes: 0
Reputation: 522787
When I create a new branch and make the new commits
This is the source of your problem. Instead of adding commits to the same feature branch, you should create a new branch from the current feature's parent and commit from there. Let's say the parent branch is master
and the feature branch has 3 commits in it. The diagram would look like this:
master: ... A -- B -- C
\
feature: M -- N -- O
When you created a new branch from feature
and started adding new commits you ended up with this:
master: ... A -- B -- C
\
feature: M -- N -- O
\
new_ft: S -- T ...
In other words, the history of feature
is part of the new branch. Instead, you can create a new branch from the B
commit in master
using:
git checkout -b new_feature <SHA-1 for commit B>
Now make your other set of commits, and then this second pull request will be essentially independent from the first one.
Upvotes: 2