microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.44k stars 28.96k forks source link

use VS code as git text editor can‘t rebase -i #92628

Closed jake-nz closed 4 years ago

jake-nz commented 4 years ago

I'm seeing this exact bug: https://github.com/Microsoft/vscode/issues/66146 I know the cause and solution but the issue is locked so I can't contribute to it Is there a way I can update the issue to help @dengdairiluo and others?

The solution Set your editor to VSCode with "wait" flag code -w git config --global core.editor "code -w"

The cause When you run EDITOR=vim git rebase -i HEAD~5

  1. .git/rebase-merge/git-rebase-todo is created
  2. vim .git/rebase-merge/git-rebase-todo is called
  3. You edit that file, save and exit vim
  4. The rebase is performed and .git/rebase-merge/git-rebase-todo is deleted

When you run EDITOR=code git rebase -i HEAD~5

  1. .git/rebase-merge/git-rebase-todo is created
  2. code .git/rebase-merge/git-rebase-todo is called
  3. VSCode is opened and the command line app code exits
  4. The rebase is performed and .git/rebase-merge/git-rebase-todo is deleted
  5. You see VSCode open to a file that doen't exist (appears empty)
vscodebot[bot] commented 4 years ago

(Experimental duplicate detection) Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

jake-nz commented 4 years ago

Adding some extra stuff in an attempt to appease @vscode-triage-bot

VS Code version: Code 1.43.0 (78a4c91400152c0f27ba4d363eb56d2835f9903a, 2020-03-09T19:34:44.548Z) OS version: Darwin x64 19.3.0

System Info |Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz (12 x 2600)| |GPU Status|2d_canvas: enabled
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: disabled_off
protected_video_decode: unavailable_off
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
viz_display_compositor: enabled_on
viz_hit_test_surface_layer: disabled_off_ok
webgl: enabled
webgl2: enabled| |Load (avg)|2, 2, 2| |Memory (System)|16.00GB (0.82GB free)| |Process Argv|| |Screen Reader|no| |VM|0%|
Extensions (16) Extension|Author (truncated)|Version ---|---|--- vscode-styled-jsx|bla|1.5.0 vscode-eslint|dba|2.1.1 xml|Dot|2.5.0 prettier-vscode|esb|3.20.0 nasc-touchbar|fel|1.12.0 svelte-vscode|Jam|0.9.3 rainbow-csv|mec|1.6.0 python|ms-|2020.2.64397 vsliveshare|ms-|1.0.1742 debugger-for-chrome|msj|4.12.6 vscode-react-native|msj|0.14.1 color-highlight|nau|2.3.0 vscode-jest|Ort|3.1.1 material-icon-theme|PKi|4.0.1 vscode-yaml|red|0.7.2 vscode-todo-highlight|way|1.0.4 (2 theme extensions excluded)
rmunn commented 4 years ago

FWIW, running EDITOR=code git rebase -i HEAD~5 fails as you describe, but running EDITOR='code -w' git rebase -i HEAD~5 does the right thing.

Also, I learned while experimenting with this that with EDITOR='code -w', you don't have to close the entire VS Code program to make Git pick up on your edits to the rebase file, it's sufficient to close the tab that the git-rebase-todo file was in. Which means that if (as I did) you had a VS Code window open beforehand, the git-rebase-todo file pops up for editing in the same VS Code window you were working in. And if you chose to squash some of the commits, the COMMIT_EDITMSG file will pop up in a new tab of the same window almost as soon as you close the git-rebase-todo tab. Handy.

IllusionMH commented 4 years ago

/question

As you correctly -w is required when you set core.editor, however as @rmunn mentioned - in your second code you don't pass -w flag to VS Code so it doesn't wait until file is closed.

rmunn commented 4 years ago

@IllusionMH This was not a question; it was an attempt to get #66146 unlocked so that this information can be posted there to help those who see that issue. Now someone will have to open yet another issue to try to get #66146 unlocked. Sigh.

IllusionMH commented 4 years ago

@rmunn Sorry! I was confused by the second VS Code example and missed part that this is answer and not related to #66146.

@bpasero could you assist with #66146 because after issue is locked there no mentions from this issue

bpasero commented 4 years ago

@IllusionMH can you clarify what I should do. Do you mean that there should be a final comment on that issue that -w is required for this to work?

IllusionMH commented 4 years ago

Maybe remove labels from this issue (because they are not correct) add link to this issue or copy answer part there.

bpasero commented 4 years ago

I unlocked that issue, feel free to update it as you see fit.