简体   繁体   中英

git rebase i vs git rebase --onto

I think I made a mistake. I wanted to delete some commit, so I used git rebase -i and deleted the last commit. But then it deleted all the changes I have made in my working directory and the stage ones. How can it be? I know I wouldn't have had this problem if I deleted some older commits. Is there a way to delete the last commit and keeping the changes in my working directory?

Btw, what is the difference between using git rebase -i and git rebase --onto <branch name>~<first commit number to remove> <branch name>~<first commit to be kept> <branch name> ?

git rebase won't launch at all if you've got uncommitted changes to known files. It'll fail with this error:

Cannot rebase: Your index contains uncommitted changes.

Some variation of that error has been around since 2007. How did you launch git rebase -i at all?

That written, your question relates to git rebase -i 's defaults. Without any arguments, it'll default to the checked-out branch, and attempt to rebase it against the <remote>/<branch> configured to be 'upstream' of the branch you've checked out. You can check the branch's upstream repository and branch with:

git config branch.<branch_name>.remote
git config branch.<branch_name>.merge

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM