4

In Visual Studio Code (VSC), I have a folder open. That folder corresponds to a local git repo whose remote repo is on GitHub. The 2 repos are synchronized.

Next, I add a file to the remote repo by manually uploading the file and committing it.

Then, I synchronize the local repo by using the sync button in VSC. After I do that, in the VSC Source Control view, it shows 1 pending change which is the file I just added to the remote repo and the file is listed as an "uncommitted" change in VSC.

This is different from how I've used Git before on the command line or on tools other than VSC, like Eclipse, for example. I'm used to how doing this type of workflow would result in a Git fast-forward where the file that was just added to the remote repo would NOT show up as an uncommitted change; rather, the file would just be available in the local repo as a result of the git-pull.

As it stands now, I have to pointlessly recommit the "uncommitted" change in my local repo each time this workflow happens just to bring the 2 repos in sync again.

I assume I'm doing something wrong in VSC or have something misconfigured in VSC.

Any thoughts/suggestions?

8
  • I’ve never used Visual Studio, but what you describe is what I would get if I did a pull configured not to fast forward and not to actually perform the merge commit, git pull --no-ff --no-commit. It’s not pointless, it’s quite a canny thing to do actually.
    – matt
    Sep 20, 2020 at 3:14
  • Yes, it does. I would never do that intentionally because I have no workflow where that would make sense. It sounds silly that VSC would have that as a default setting. I wonder where the settings are for git pull/merge/sync in VSC so I could change it?
    – Kevin
    Sep 20, 2020 at 3:17
  • 1
    No idea, I’m just pointing out that it’s not insane. Also maybe in VS Sync means this and there’s something else that means your kind of pull.
    – matt
    Sep 20, 2020 at 3:20
  • you can view the git commands executed in the OUTPUT - Git panel. What happens if you do a git pull from the command line?
    – rioV8
    Sep 20, 2020 at 7:50
  • $ git pull remote: Enumerating objects: 2, done. remote: Counting objects: 100% (2/2), done. remote: Compressing objects: 100% (2/2), done. remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 2 Unpacking objects: 100% (4/4), done. From github.com:<myaccount>/<myproject> 131a8ca..1ed0da8 gh-pages -> origin/gh-pages 0859b9d..5472c3d master -> origin/master Updating 131a8ca..1ed0da8 Fast-forward <the file manually uploaded to github> | Bin 0 -> 190370 bytes 1 file changed, 0 insertions(+), 0 deletions(-)create mode 100644 <the file manually uploaded to github>
    – Kevin
    Sep 20, 2020 at 13:32

4 Answers 4

4

It turns out this has nothing to do with VSC. The solution to the problem is actually based on SMB mount settings for file permissions and git configuration settings for file permission sensitivity.

The solution is described here.

0

There is an extension called rysnc which can be used to achieve this.

Sync-Rsync the documentation is clear about it's functionality.

for more about it's discussion here's a similar issue:

https://github.com/microsoft/vscode-remote-release/issues/196

1
  • An extension that uses rsync isn't the solution to the problem. I would like to focus on why native VSC features don't behave the way I expect other git client tools to behave and I would like to change how VSC works for me. I assume others have VSC working with git the way I'm expecting VSC to work.
    – Kevin
    Sep 20, 2020 at 13:38
0

First, make sure you do have a commit before the VSCode Sync.
You should see:

https://i.imgur.com/O4SPXoT.png

Second, I would advise a rebase when syncing, by setting the VSCode git.rebaseWhenSync to true.

That should replay your commit, making sure the committed file remains committed.

7
  • I know that rebasing is unnecessary because I can successfully use the git command line or the Git tooling in Eclipse on another repository and successfully merge without rebasing to achieve the desired result. Upon further investigation in my local git repository where I'm having the problem, using git on the command line produces the same undesirable result as in VSC...so I have to conclude that the problem is not with VSC; rather, the problem is with how I'm using git in that particular repository or that particular local repository. i.e. git fetch then git merge produces the same result.
    – Kevin
    Sep 26, 2020 at 22:58
  • Still, try the rebase option, for testing, just to check if, in this particular instance, it would help.
    – VonC
    Sep 27, 2020 at 5:49
  • I enabled the VSC rebase when sync setting and tried to sync again after I uploaded a file to the GitHub repository manually. I got the same result...the file that I just uploaded now shows as an uncommitted local file change.
    – Kevin
    Sep 27, 2020 at 12:26
  • @Kevin And yet, it was committed before the sync?
    – VonC
    Sep 27, 2020 at 12:28
  • Indeed. I had a commit queued up for the sync prior to changing the setting to rebase when syncing. After the sync, the file I had committed locally showed up correctly in the remote repo. But, I still have the uncommitted local file change for the file that was uploaded manually to GitHub. Note that the commit I did before the sync was for a completely different file than the one that was uploaded manually to GitHub. I'm not sure if you expected them to be the same file or not for this test ... it's not realistic for them to be the same file so I won't even attempt that.
    – Kevin
    Sep 27, 2020 at 12:44
0

When you manually uploaded and commit the file to github, it was created in your working directory, but never committed to your local repo. So naturally in the source control view (essentially git status) it shows up as uncommitted.

To avoid confusions, I would change your workflow to never upload a file directly to the remote repo. Instead, commit it to your local repo first and push to remote.

1
  • When I manually uploaded and committed the file to github, it has nothing to do with my working directory and it obviously hasn't been committed to my local repo. The git status command has no knowledge of what went on at this point. I don't think it's reasonable to suggest a change to my workflow because the point of git is that anyone, not just me, could upload to github without my knowledge and I want to be able to merge that into my local repo.
    – Kevin
    Sep 26, 2020 at 22:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.