Skip to content

Instantly share code, notes, and snippets.

@nickretallack
Last active December 14, 2015 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickretallack/5087584 to your computer and use it in GitHub Desktop.
Save nickretallack/5087584 to your computer and use it in GitHub Desktop.
This has worked in the past, but no longer works. I'm attempting to do a rebase like the one described in git rebase --help as "git rebase --onto master next topic". Specifically, I'm trying to copy a range of commits from one branch onto another. Currently, I can't get git to do this. It appears to ignore --onto and --root, and just use the bar…
Nicholass-MacBook-Air-5:test-git nick$ git init
Initialized empty Git repository in /Users/nick/test-git/.git/
Nicholass-MacBook-Air-5:test-git nick$ touch file
Nicholass-MacBook-Air-5:test-git nick$ git add file
Nicholass-MacBook-Air-5:test-git nick$ git commit -am "first commit"
[master (root-commit) dd1c9fd] first commit
0 files changed
create mode 100644 file
Nicholass-MacBook-Air-5:test-git nick$ git checkout -b branch1
Switched to a new branch 'branch1'
Nicholass-MacBook-Air-5:test-git nick$ cat > file
line
Nicholass-MacBook-Air-5:test-git nick$ git commit -am "edited the file"
[branch1 6f19cab] edited the file
1 file changed, 1 insertion(+)
Nicholass-MacBook-Air-5:test-git nick$ git checkout master
Switched to branch 'master'
Nicholass-MacBook-Air-5:test-git nick$ git checkout -b branch2
Switched to a new branch 'branch2'
Nicholass-MacBook-Air-5:test-git nick$ git rebase --onto branch2 master branch1
Switched to branch 'branch1'
Current branch branch1 is up to date.
Nicholass-MacBook-Air-5:test-git nick$ # WTF!
Nicholass-MacBook-Air-5:test-git nick$ git checkout branch2
Switched to branch 'branch2'
Nicholass-MacBook-Air-5:test-git nick$ git rebase --onto branch2 --root master branch1
First, rewinding head to replay your work on top of it...
Fast-forwarded branch2 to branch2.
Nicholass-MacBook-Air-5:test-git nick$ # WTF again!
@offby1
Copy link

offby1 commented Mar 5, 2013

I wonder if this is what you're trying to do:

git init
touch file
git add file
git commit -am "first commit"
git checkout -b branch1
echo egads > file
git commit -am "edited the file"
git branch -v
git checkout -b branch2 master
git rebase --onto branch1 branch2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment