VS2017下使用Git遇到的问题
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VS2017下使用Git遇到的问题相关的知识,希望对你有一定的参考价值。
我在使用最新版的VS2017时,想获取服务器上最新代码,Fetch到了最新修改,但是在拉取代码的时候出现了问题
[email protected] MINGW64 /d/demo/myrepos (dev-css)
$ git pull origin dev-css
From https://winleechina.visualstudio.com/_git/PartTimeJob
* branch dev-css -> FETCH_HEAD
error: Your local changes to the following files would be overwritten by merge:
BaseSite/Code/.vs/BaseSite/v15/Server/sqlite3/storage.ide-shm
BaseSite/Code/.vs/BaseSite/v15/Server/sqlite3/storage.ide-wal
BaseSite/Code/.vs/BaseSite/v15/sqlite3/storage.ide-shm
BaseSite/Code/.vs/BaseSite/v15/sqlite3/storage.ide-wal
Please commit your changes or stash them before you merge.
Aborting
Updating d568290..cf89950
[email protected] MINGW64 /d/demo/myrepos (dev-css)
$ git status
On branch dev-css
Your branch is behind ‘origin/dev-css‘ by 8 commits, and can be fast-forwarded.
(use "git pull" to update your local branch)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: BaseSite/Code/.vs/BaseSite/v15/Server/sqlite3/storage.ide-shm
modified: BaseSite/Code/.vs/BaseSite/v15/sqlite3/storage.ide-shm
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitattributes
.gitignore
no changes added to commit (use "git add" and/or "git commit -a")
于是我采用常规套路(签入,或者撤销checkout) 都是失败,而且不能undo change其中两个文件storage.ide-shm/storage.ide-shm;
这个问题的最终结果就是导致我不能拉取最新代码。
好在在StackOverflow发现如下方法
text git rm [path_and_filename] --cached //该命令将永远不想签入的文件从索引(index)中移除,如果不想这个文件存在磁盘上,可以使用git rm [path_and_filename] --force
将操作后的文件(此时已经是staged)提交就好了
Ps:
.gitignore 是最先想到的方法,但是也不行,不过SO上有人貌似是可以的,如下:
# Visual Studio 2015 cache/options directory .vs/
微软官档:
Permanently ignore changes to a file
If a file is already tracked by Git, adding that file to your .gitignore is not enough to ignore changes to the file. You also need to remove the information about the file from Git‘s index
These steps will not delete the file from your system. They just tell Git to ignore future updates to the file.+- Add the file in your .gitignore.
Run the following:
git rm --cached
Commit the removal of the file and the updated .gitignore to your repo.
参考地址:
- .gitignore for C#: https://github.com/github/gitignore/blob/master/VisualStudio.gitignore#L28
- https://stackoverflow.com/questions/45016619/what-is-the-storage-ide-file-beneath-my-visual-studio-solution-folder-and-wha
- https://stackoverflow.com/questions/45802083/visual-studio-2017-15-3-0-git-changes-include-storage-ide-even-though-vs-in
- https://docs.microsoft.com/en-us/vsts/git/tutorial/ignore-files?tabs=visual-studio
以上是关于VS2017下使用Git遇到的问题的主要内容,如果未能解决你的问题,请参考以下文章