0

I cloned a project repository and did some commits to it. The commits were pretty dirty; I messed up tabs-spaces and committed some trash along the way. So before making a pull request I want to make things tidy. I think the best way would be making a new branch at origin/master and then apply commits from my old branch one by one to a working copy and doing clean commits to a new branch.

So how to apply commit from other branch to a working copy? Is it the best way to do it? Such task seems pretty common and maybe there is already an established workflow and tools for such things?

Poma
  • 8,174
  • 18
  • 82
  • 144
  • see [cleaning commit history](http://stackoverflow.com/questions/7947322/preferred-github-workflow-for-updating-a-pull-request-after-code-review/15055649#15055649) - the command you are effectively looking for is [rebase](http://git-scm.com/book/en/v2/Git-Branching-Rebasing). – AD7six Mar 19 '15 at 03:11
  • I don't want to just sqash my commits (as in provided answer); I want to edit each commit before applying it to fix things – Poma Mar 19 '15 at 03:15
  • It's the same process, and still using rebase. (try it/read about it before commenting). – AD7six Mar 19 '15 at 03:17
  • Ah I see. It's a good thing to read a manual first ^_^. Thank you I think this is the answer. – Poma Mar 19 '15 at 03:19
  • 1
    See http://git-scm.com/book/en/v2/Git-Tools-Rewriting-History –  Mar 19 '15 at 03:21

1 Answers1

0

Let's say the work tree is something like:

img

and you want to apply only g-h to the origin/master. First off, create a new branch using origin/master, and another for commits upto h only:

git checkout -b new-branch origin/master
git checkout -b daughter-branch h

Now, apply commits from g onwards

git rebase --onto new-branch g^
hjpotter92
  • 78,589
  • 36
  • 144
  • 183