I have a branch, where I did some changes, but I'd originally mistaken and create it from wrong branch, so I have many different changes I don't want to have in it. So how can I clean it so I only have changes I've done and changes from master branch?
相关问题
- Why does recursive submodule update from github fa
- Extended message for commit via Visual Studio Code
- Emacs shell: save commit message
- Can I organize Git submodules in a flat hierarchy?
- Upload file > 25 MB on Github
相关文章
- 请教Git如何克隆本地库?
- GitHub:Enterprise post-receive hook
- Git Clone Fails: Server Certificate Verification F
- SSIS solution on GIT?
- Is there a version control system abstraction for
- ssh: Could not resolve hostname git: Name or servi
- Cannot commit changes with gitextensions
- git: retry if http request failed
If your changes are all made on top of the upstream branch (i.e. you don't have any merge commits from upstream mixed in with your changes), you can just rebase it on top of master.
Assuming that your branch is up-to-date with respect to the upstream, that's just
Afterwards, you might want to change the tracking branch of your current branch to master:
(or just git branch -u origin/master with git >=1.8)
You can create a new branch from master and then cherry-pick the changes you have made into the new branch.
Find the commit hashes for every commit you want to save. Then:
cherry-pick
ing single commits can be tedious, when you have a lot of them. Since git 1.7.2+cherry-pick
can handle commit ranges.As EOL pointed out in the comments, cherry-pick applies each patch in turn and waits for the user to commit it, if there are conflicts. In this case, resolve the conflicts and do a
git cherry-pick --continue
to automatically move to the next commit. Or usegit cherry-pick --abort
to abort the whole operation.Now inspect your current branch. If everything worked well, you can delete the previous messed-up branch:
See the git cherry-pick manual page for further details.
Edit: included info about
git cherry-pick --continue
, which EOL mentioned in the comments.Update
You mentioned you want to cherry-pick only those commit you created. This can be done with this little bash script: