microsoft / vscode

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

cut error "Git: the following file has staged content different from both the" #102491

Closed lorenzznerol closed 4 years ago

lorenzznerol commented 4 years ago

Version: 1.47.0 (user setup) Commit: d5e9aa0227e057a60c82568bf31c04730dc15dcd Date: 2020-07-09T08:01:16.801Z Electron: 7.3.2 Chrome: 78.0.3904.130 Node.js: 12.8.1 V8: 7.8.279.23-electron.0 OS: Windows_NT ia32 10.0.18363

Steps to Reproduce:

(I could not reproduce this, probably it has only occured due to a renaming of parent folder, the error message is cut anaway)

  1. In terminal, with git installed, open a new git folder, start it with git init (or use the Source Control button "Initialize Repository") and use for example: git clone "https://github.com/redhat-developer/vscode-java.git"
  2. git add --all > the whole folder is added to the stage.

image

  1. Change a file slightly (or just saving it again should already be a change I think). In my case, I changed "Additional Informations" to "Additional Information"

image

  1. If you now just want to unstage all again:

image

  1. cut error message "Git: the following file has staged content different from both the": image

  2. press open git log, in the log we see now the uncut error message at the bottom.

git for-each-ref --sort -committerdate --format %(refname) %(objectname) git remote --verbose git config --get commit.template git branch git rm --cached -r -- d:\Stack Overflow\vscode_git\vscode-java error: the following file has staged content different from both the file and the HEAD: vscode-java (use -f to force removal)

Does this issue occur when all extensions are disabled?: Untested, but no of course, as the error refers to git in the message, thus the error only occurs when using git, which is built-in. Git version 2.27.0

joaomoreno commented 4 years ago

Why are you trying to stage an entire git repository inside another repository?

lorenzznerol commented 4 years ago

The main reason for this is a mistake, I am still a clear biginner at git, even after a couple of tutorials and quite a few first applications. The reason here is that I have cloned the repo from github into a folder that I had mistakenly initialized as repo right before cloning. I stayed in that parent folder into that I had cloned. After cloning, the structure was like "vscode_git\vscode-java\" and I still was in the "vscode_git\" directory, though the actual project was the "vscode-java\" directory. Now I found that I could not effectively add and commit a file, as it was then a file of the subdirectory "vscode-java\". The only way to see the files in the staging was to add all in one, using git add . / git add -A / git add --all. This was nothing I wanted to do, it was more during testing of some code from a tutorial, of course adding all is wrong. I have finally understood my mistake, the pull request from a forked clone and from the actual project folder is done now.

This question here is only about the cut message text. It is not that important anymore what I actually wanted to do here? One might avoid the cut of the message, and one might add a hint in these cases like "Please check if you are in the right git directory, you might be in a parent or sub directory." or something like that of course. If I am not mistaken again here.

joaomoreno commented 4 years ago

Got it. We try our best to forward git's messages to the user, but sometimes git itself wrongly formats the message, making it really hard. That's why the Open Git Log button is there, so you actually get to see the entire message. Closing this as designed.

lorenzznerol commented 4 years ago

I understand it is a formatting issue of git, but this is not entirely true. They simply insert a linebreak here to have a better output in the git log, which is nothing impossible to track. vscode will probably have this again elsewhere, that is why I would rather not close this "as designed". To a new user, it is also not even clear that she can look at the git log to see the full error message, though it may seem clear to a professional.