Here is my situation: I have a production branch, a dev branch and branches for features. While I was working on a feature I has to do a hotfix on the dev branch. Now I to rebase the feature branch I am currently working on to avoid future merging conflicts. When I used to use IDEs from JetBrain I would do a git rebase and it would do the trick. The only command I found in VSCode is Git: Sync(rebase) but this does not do anything and does not rebase. All I get is this message:
This action will push and pull commit to and from 'origin/Current_feature'
Anyone have experience with this?
Once you have your commits ready, we can click the Start Rebase button. You will then be presented with a screen in VS Code to reword your commit message. Write your new message, and save and close the file to continue. After this, our rebase is complete.
Click Rebase. You'll see a prompt to rebase the changes from your current branch, and then a drop-down to specify which branch the changes in the current branch should be replayed on top of. If there's a conflict, resolve it just like you resolve merge conflicts in Visual Studio.
This wrapper for git pull --rebase provides a way to rebase while pulling (that is, to fetch and then rebase on the remote branch), but not a way to rebase HEAD on an arbitrary commit. – Rory O'Kane. Jan 29, 2019 at 3:00. 4. This only rebases your local commits on top of new pulled-in commits in the same branch.
I don't think Visual Studio Code has Git rebase functionality built-in. If you want to do your rebasing in Visual Studio Code instead with the git
command-line tool or with a Git GUI, you can install the GitLens extension for VS Code.
GitLens’s README indicates that GitLens supports rebasing. It says that when viewing branches, the context menu for each branch includes these commands:
And when viewing the commits in one branch, the context menu for each commit includes this command:
I just tried, it works!!
PS: I try to find the approach to setting the default "Sync" action with --rebase
paramter. I find the PR of Added config option to sync+Rebase from statusbar, but it haven't landed.
Finally find the solution, git config --global pull.rebase true
and it works!!
You could run the command directly from your terminal with:
git rebase branch
or git rebase -i branch
You will have to configure your gitconfig to use vscode for the interactive rebase.
Something like:
[core]
editor = code --wait
Or by setting your envar to GIT_EDITOR=code\ --wait
As soon as you want to do something a bit out of the ordinary, using the command line yield better results.
Looks like this VS Code PR introduced a new git.rebaseWhenSync
option:
https://github.com/microsoft/vscode/pull/52527
I tested it and it looks like it works as expected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With