我在使用最新版的VS2017时,想获取服务器上最新代码,Fetch到了最新修改,但是在拉取代码的时候出现了问题

user@user-PC 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 user@user-PC 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发现如下方法

    git rm [path_and_filename] --cached  //该命令将永远不想签入的文件从索引(index)中移除,如果不想这个文件存在磁盘上,可以使用git rm [path_and_filename] --force
  1. 将操作后的文件(此时已经是staged)提交就好了

Ps:

  1. .gitignore 是最先想到的方法,但是也不行,不过SO上有人貌似是可以的,如下:
 # Visual Studio 2015 cache/options directory
.vs/
  1. 微软官档:

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.+
1. Add the file in your .gitignore.
2. Run the following:
> git rm --cached <file>
3. Commit the removal of the file and the updated .gitignore to your repo.

参考地址:

  1. .gitignore for C#: https://github.com/github/gitignore/blob/master/VisualStudio.gitignore#L28
  2. https://stackoverflow.com/questions/45016619/what-is-the-storage-ide-file-beneath-my-visual-studio-solution-folder-and-wha
  3. https://stackoverflow.com/questions/45802083/visual-studio-2017-15-3-0-git-changes-include-storage-ide-even-though-vs-in
  4. https://docs.microsoft.com/en-us/vsts/git/tutorial/ignore-files?tabs=visual-studio

Ps2: 加一个描述更详细的说明

参考地址:http://www.pfeng.org/archives/840


1. 关于将已经ignore的文件(夹)重新加入跟踪里面

重新添加已经被忽略过的文件(夹)

重新添加已经被忽略过的文件时,我们仅仅使用git add是不行的,因为git仓库中根本没有那个文件,这时候我们需要加上-f参数来强制添加到仓库中,然后在提交。比如上面设置了忽略排除的文件TokenGuard.php我们需要重新加入

git add -f [文件(夹)名]

然后在commit和push就行了


2. 关于VS中经常出现的error: Your local changes to the following files would be overwritten by merge:

error: Your local changes to the following files would be overwritten by merge:

意思是我本地上新修改的代码的文件,将会被git服务器上的代码覆盖;我当然不想刚刚写的代码被覆盖掉,看了git的手册,发现可以这样解决:

方法1:如果你想保留刚才本地修改的代码,并把git服务器上的代码pull到本地(本地刚才修改的代码将会被暂时封存起来)

 git stash
git pull origin master
git stash pop

如此一来,服务器上的代码更新到了本地,而且你本地修改的代码也没有被覆盖,之后使用add,commit,push 命令即可更新本地代码到服务器了。

方法2、如果你想完全地覆盖本地的代码,只保留服务器端代码,则直接回退到上一个版本,再进行pull:

 git reset --hard
git pull origin master

注:其中origin master表示git的主分支。

VS2017下使用Git遇到的问题的更多相关文章

  1. VS2017 下使用 git. git服务器使用gitblit

    注意事项: 创建的GIT不要包括有中文, 不然会不成功的..... gitblit安装及配置及客户端下载略过...... 可参考:  https://www.cnblogs.com/jeremylee ...

  2. VS2017中使用Git进行版本控制

    简单介绍在VS2015下使用Git来管理项目 1. VS2017启用Git源代码管理插件 第一步,打开vs: 第二步,打开[团队资源管理器]: 第三步,选择团队管理器选项卡下的[连接]页面,点击[克隆 ...

  3. 在Centos下搭建git并可以通过windows客户端访问

    亲测在本地虚拟机和远程服务器上无问题,如有不懂请留言. 注意事项:以下所有操作是在root权限下操作的.1.Centos服务器版本centos6.5 2.首先安装git,使用yum在线安装 yum i ...

  4. ***Linux下使用git命令及github项目

    在linux下搭建git环境1.创建Github账号,https://github.com2.Linux创建SSH密钥: ssh-keygen  ##一直默认就可以了 3.将公钥加入到Github账户 ...

  5. Linux下安装Git

    Ubuntu12.04中默认没有安装Git.需要自行安装. 1. 安装Git 1.1 Ubuntu12.04下 可以使用apt-get方式安装,也可以下载源代码安装[1],我们这里使用apt-git安 ...

  6. Windows 环境下配置 git bash 的 HOME 默认路径

    0.引 在 windows 下安装 git 之后, git 默认的HOME和~路径一般都是C:\Users\用户名,每次得用命令切换到常用的Repository下,此操作重复而没有意义.为了修改默认路 ...

  7. windows下安装git & 在git@OSC上推送代码

    第一部分 windows下安装git 1.下载最新版本的git:直接百度“git”,如图所示,点击立即下载. 也可以直接在官网下载最新版本的git:http://www.git-scm.com/dow ...

  8. Windows下搭建Git开发环境

    Windows下搭建Git开发环境主要有以下三种方法: 1,VS,vs2013和vs2015中已经集成了git插件了 2,msysGit+TortoiseGit 3,msysGit+SourceTre ...

  9. Android 源码获取-----在Windows环境下通过Git得到Android源代码

    在学习Android的过程中,深入其源代码研究对我们来说是非常重要的,这里将介绍如何通过在Windows环境下使用Git来得到我们的Android源代码. 1.首先确保你电脑上安装了Git,这个通过  ...

随机推荐

  1. 分布式系列九: kafka

    分布式系列九: kafka概念 官网上的介绍是kafka是apache的一种分布式流处理平台. 最初由Linkedin开发, 使用Scala编写. 具有高性能,高吞吐量的特定. 包含三个关键能力: 发 ...

  2. 基于Python的Webservice开发(一)-简介

    之前为了解决Webservice的开发,直接用Python自带的CGI模块挂在IIS上. 但是该方式开发Soap的接口,需要大量的开发,而且安全方面也存在很多问题. 我推荐关于用Python开发Web ...

  3. 吴恩达《机器学习》课程笔记——第七章:Logistic回归

    上一篇  ※※※※※※※※  [回到目录]  ※※※※※※※※  下一篇 7.1 分类问题 本节内容:什么是分类 之前的章节介绍的都是回归问题,接下来是分类问题.所谓的分类问题是指输出变量为有限个离散 ...

  4. python多任务抓取图片

    import re import urllib.request import gevent def download(image_download, images_path,i): headers = ...

  5. Sping 里面的适配器模式的实现

    适配器模式----------设计模式最近在看SpringMVC源码,从中看到了比较优秀的设计模式所以来分享下. 1.适配器模式(Adapter):将一个类的接口转换成客户希望的另外一个接口,Adap ...

  6. 2019前端面试题之js

    1.js的数据类型 js的数据类型分为基本类型跟引用类型 基本数据类型(5个):undefined,boolean,number,string,null.基本类型的访问是按值访问的,就是说你可以操作保 ...

  7. EntityFramework6之原生SQL

    原文:https://www.cnblogs.com/wujingtao/p/5412329.html 用EF执行SQL又比ADO.NET方便,特别是在执行查询语句的时候,EF会把查询到的数据自动保存 ...

  8. Centos系统FastDFS搭建与排错

    FastDFS中Tracker server主要是负载均衡和调度,Storage server主要是文件存储. 1.1 系统环境 [root@ centos fastdfs]# cat /etc/re ...

  9. 【Python】Flask中@wraps的使用

    先说总结,白话来讲,@wraps相当于是装饰器的装饰器. python内置的方法使用解释,看起很复杂的样子┓( ´∀` )┏ def wraps(wrapped, assigned = WRAPPER ...

  10. 记录一个pom文件

    rt <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://m ...