git: How to rebase all commits by one certain author into a separate branch?

前端 未结 2 785
花落未央
花落未央 2021-02-05 23:54

I\'m using some code for which no SCM is used+ and receive occasional updates in the form of all project files although only some of them have been changed only a bit

相关标签:
2条回答
  • 2021-02-06 00:40

    I'm not quite understanding what you are doing, but the problem you describe with a third party codebase, is called a "vendor branch". Here is how I would handle it:

    Make a branch for the third party version, e.g. vendor. I assume your branch is called master. When they publish a new version, you can do the following:

    git stash # If you have any uncommitted files
    git checkout vendor
    tar -xzvf [new files]  # This might be unzip or whatever, rather than tar
    git commit -am "Version xxx from upstream"  # Adjust commit message to suit
    git checkout master
    git merge vendor   # Bring changes into your branch (you could use rebase here if you prefer to keep all your changes on top of all their changes)
    git stash pop # Restore your uncommitted files
    

    ps. rather than git add -p, I'd use git gui. I was sceptical of using a gui to begin with, but I couldn't live without git gui and gitk now (or gitx on a mac).

    0 讨论(0)
  • 2021-02-06 00:41

    I recently did this for someone:

    git checkout -b other_work <sha1_of_where_to_rebase>
    git log --reverse --author=others --format=%H <sha1_range> | xargs -n 1 git cherry-pick
    

    Hope this helps

    0 讨论(0)
提交回复
热议问题