Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git rebase in Visual Studio Code

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?

like image 273
Chsir17 Avatar asked Jul 17 '18 12:07

Chsir17


People also ask

How do I rebase in VS Code?

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.

How do I rebase in Visual Studio git?

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.

What is pull rebase in VS Code?

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.


4 Answers

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:

  • Rebase (Interactive) Branch (via Terminal)
  • Rebase (Interactive) Branch to Remote (via Terminal)

And when viewing the commits in one branch, the context menu for each commit includes this command:

  • Rebase to Commit (via Terminal) (when available)
like image 98
Rory O'Kane Avatar answered Oct 13 '22 05:10

Rory O'Kane


I just tried, it works!! enter image description here

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!!

like image 42
Gavin Avatar answered Oct 13 '22 04:10

Gavin


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.

like image 13
Marc Simon Avatar answered Oct 13 '22 05:10

Marc Simon


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.

like image 6
Tomáš Hübelbauer Avatar answered Oct 13 '22 04:10

Tomáš Hübelbauer