Repository: vscode
Issue: Git - "Stage selected range" doesn't change diff view instantly
Labels: bug,git

Type: <b>Bug</b>

### Reproduce steps

1. Open a Git repository and change some files
2. Open the diff view from "Changes" in "SOURCE CONTROL" panel
3. Stage a part of changed lines by "Stage selected range" in the upper right corner

Now staged changes have been added to "Staged Changes" in "SOURCE CONTROL" panel.

## Problem

#### Expectation

Staged changes are not highlighted in diff view of "Changes".

#### Actual

Staged changes are still highlighted in diff view of "Changes".

VS Code will refresh "Changes" in the background to correct state if:
- a periodic refresh is triggered after several seconds
- reopen diff view of "Changes" in "SOURCE CONTROL" pannel
- open another diff view from "Staged Changes" in "SOURCE CONTROL" pannel

#### More information

The problem only happens in recent 1 or 2 versions of VS Code.

## Git Output

stage lines
```
[2022-09-27T08:42:01.458Z] > git hash-object --stdin -w --path deploy/engine.py [4ms]
[2022-09-27T08:42:01.495Z] > git show -s --format=%H%n%aN%n%aE%n%at%n%ct%n%P%n%D%n%B -z HEAD [14ms]
[2022-09-27T08:42:01.521Z] > git ls-tree -l HEAD -- deploy/engine.py [3ms]
[2022-09-27T08:42:01.548Z] > git update-index  --cacheinfo 100644 ffe5b64d4fdff19195809962c2e4074e5008aa4d
 deploy/engine.py [2ms]
[2022-09-27T08:42:01.548Z] Ignoring path 
[2022-09-27T08:42:01.584Z] > git status -z -uall [13ms]
[2022-09-27T08:42:01.610Z] > git symbolic-ref --short HEAD [3ms]
[2022-09-27T08:42:01.636Z] > git for-each-ref --format=%(refname)%00%(upstream:short)%00%(objectname)%00%(upstream:track)%00%(upstream:remotename)%00%(upstream:remoteref) refs/heads/test/905 refs/remotes/test/905 [3ms]
[2022-09-27T08:42:01.687Z] > git for-each-ref --sort -committerdate --format %(refname) %(objectname) %(*objectname) [27ms]
[2022-09-27T08:42:01.699Z] > git remote --verbose [13ms]
[2022-09-27T08:42:01.735Z] > git config --get commit.template [1ms]
```

after several seconds
```
[2022-09-27T08:50:56.688Z] > git ls-files --stage -- /home/xhtang/crypto-platform/deploy/engine.py [2ms]
[2022-09-27T08:50:56.715Z] > git cat-file -s ffe5b64d4fdff19195809962c2e4074e5008aa4d [2ms]
[2022-09-27T08:50:56.934Z] > git show --textconv :deploy/engine.py [5ms]
```

open another diff view from "Staged Changes"
```
[2022-09-27T08:52:10.754Z] > git show --textconv HEAD:deploy/engine.py [74ms]
[2022-09-27T08:52:10.754Z] > git show --textconv :deploy/engine.py [50ms]
[2022-09-27T08:52:10.754Z] > git ls-files --stage -- /home/xhtang/crypto-platform/deploy/engine.py [5ms]
[2022-09-27T08:52:10.771Z] > git ls-tree -l HEAD -- /home/xhtang/crypto-platform/deploy/engine.py [45ms]
[2022-09-27T08:52:10.776Z] > git cat-file -s ffe5b64d4fdff19195809962c2e4074e5008aa4d [6ms]
```


### VS Code version

VS Code version: Code 1.71.2 (74b1f979648cc44d385a2286793c226e611f59e7, 2022-09-14T21:12:14.256Z)
OS version: Linux x64 5.15.0-46-generic snap
Modes:
Sandboxed: No
Remote OS version: Linux x64 4.14.252-195.483.amzn2.x86_64
Connection to 'SSH: jp23' could not be established  Canceled
Remote OS version: Linux x64 3.10.0-1160.el7.x86_64

<details>
<summary>System Info</summary>

|Item|Value|
|---|---|
|CPUs|Intel(R) Core(TM) i7-10700F CPU @ 2.90GHz (16 x 2900)|
|GPU Status|2d_canvas: enabled<br>canvas_oop_rasterization: disabled_off<br>direct_rendering_display_compositor: disabled_off_ok<br>gpu_compositing: enabled<br>multiple_raster_threads: enabled_on<br>opengl: enabled_on<br>rasterization: enabled<br>raw_draw: disabled_off_ok<br>skia_renderer: enabled_on<br>video_decode: disabled_software<br>video_encode: disabled_software<br>vulkan: disabled_off<br>webgl: enabled<br>webgl2: enabled<br>webgpu: disabled_off|
|Load (avg)|1, 1, 1|
|Memory (System)|31.27GB (17.78GB free)|
|Process Argv|--no-sandbox --force-user-env --unity-launch --crash-reporter-id c2657820-dce9-4175-9fcd-e0d95f669ff2|
|Screen Reader|no|
|VM|0%|
|DESKTOP_SESSION|ubuntu|
|XDG_CURRENT_DESKTOP|Unity|
|XDG_SESSION_DESKTOP|ubuntu|
|XDG_SESSION_TYPE|x11|

|Item|Value|
|---|---|
|Remote|SSH: jp08|
|OS|Linux x64 4.14.252-195.483.amzn2.x86_64|
|CPUs|Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz (8 x 2499)|
|Memory (System)|31.07GB (23.98GB free)|
|VM|0%|

Connection to 'SSH: jp23' could not be established  Canceled

|Item|Value|
|---|---|
|Remote|SSH: bj01|
|OS|Linux x64 3.10.0-1160.el7.x86_64|
|CPUs|Intel(R) Xeon(R) Gold 6248 CPU @ 2.50GHz (80 x 2500)|
|Memory (System)|503.10GB (465.41GB free)|
|VM|0%|
</details><details><summary>Extensions (20)</summary>

Extension|Author (truncated)|Version
---|---|---
jupyter-keymap|ms-|1.0.0
remote-ssh|ms-|0.84.0
remote-ssh-edit|ms-|0.80.0
remote-wsl|ms-|0.66.3
vscode-markdownlint|Dav|0.48.1
githistory|don|0.6.19
gitlens|eam|12.2.2
vscode-terminals|fab|1.13.0
copilot|Git|1.46.6822
python|ms-|2022.14.0
vscode-pylance|ms-|2022.9.40
jupyter|ms-|2022.8.1002431955
jupyter-keymap|ms-|1.0.0
jupyter-renderers|ms-|1.0.9
cpptools|ms-|1.12.4
hexeditor|ms-|1.9.8
indent-rainbow|ode|8.3.1
trailing-spaces|sha|0.4.1
code-spell-checker|str|2.8.0
pdf|tom|1.2.0


</details><details>
<summary>A/B Experiments</summary>

```
vsliv368:30146709
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492:30256859
vslsvsres303:30308271
pythonvspyl392:30443607
vserr242:30382549
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263cf:30335440
vscorecescf:30445987
pythondataviewer:30285071
vscod805cf:30301675
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411cf:30557515
vsaa593cf:30376535
pythonvs932:30410667
cppdebug:30492333
vsclangdc:30486549
c4g48928:30535728
hb751961:30553087
dsvsc012cf:30540253
azure-dev_surveyone:30548225
2144e591:30553903
fc301958:30573243

```

</details>

<!-- generated by issue reporter -->