Git clean branch to save only my changes and changes from master -


i have branch, did changes, i'd mistaken , create wrong branch, have many different changes don't want have in it. how can clean have changes i've done , changes master branch?

you can create new branch master , cherry-pick changes have made new branch.

find commit hashes every commit want save. then:

git checkout master git checkout -b <new branch name> git cherry-pick <commit hash> # every commit want save 

cherry-picking single commits can tedious, when have lot of them. since git 1.7.2+ cherry-pick can handle commit ranges.

git cherry-pick <first commit save>^..<last commit save> 

as eol pointed out in comments, cherry-pick applies each patch in turn , waits user commit it, if there conflicts. in case, resolve conflicts , git cherry-pick --continue automatically move next commit. or use git cherry-pick --abort abort whole operation.

now inspect current branch. if worked well, can delete previous messed-up branch:

git branch -d <old messed branch name> 

see git cherry-pick manual page further details.

edit: included info git cherry-pick --continue, eol mentioned in comments.


update

you mentioned want cherry-pick commit created. can done little bash script:

author_name="your git author name" start_commit="earliest commit hash cherry-pick" end_commit="latest commit hash cherry-pick"  git rev-list --reverse --topo-order "$start_commit^..$end_commit" | while read rev   commit_author_name=`git log --pretty=format:"%an%n" -n 1 $rev`   if [[ $commit_author_name == *"$author_name"* ]];     git cherry-pick $rev || break   fi done 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -