覆盖 Git 中的本地更改

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29389637/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 10:51:26  来源:igfitidea点击:

Overwriting local changes in Git

gitvisual-studio

提问by David Klempfner

I am using Git in Visual Studio and am getting this error when trying to pull:

我在 Visual Studio 中使用 Git 并在尝试拉取时收到此错误:

An error occurred. Detailed message: 1 uncommitted change would be overwritten by merge

However when I try and commit it won't let me because I have to pull first, so it's a vicious cycle.

但是,当我尝试提交时它不会让我因为我必须先拉,所以这是一个恶性循环。

There doesn't seem to be anything much on how to fix this error from within Visual Studio.

关于如何从 Visual Studio 中修复此错误,似乎没有任何说明。

How can I just get the latest version on the server and overwrite my local changes?

我怎样才能在服务器上获取最新版本并覆盖我的本地更改?

采纳答案by poke

How can I just get the latest version on the server and overwrite my local changes?

我怎样才能在服务器上获取最新版本并覆盖我的本地更改?

In the Team Explorerwindow, in the list of pending changes (that's also where you create commits), you can right click on files and then click “Undo…” to undo whatever local changes you did to those files. Then you should be able to pull.

团队资源管理器窗口中,在待定更改列表(这也是您创建提交的位置)中,您可以右键单击文件,然后单击“撤消...”以撤消您对这些文件所做的任何本地更改。然后你应该可以拉。

However, you shouldn't need to pull just to commit. Git commits to your local repository, the state of other remote repository is never considered for commits.

但是,您不应该只是为了提交而拉取。Git 提交到您的本地存储库,从不考虑其他远程存储库的状态进行提交。

There are "out going commits", but when I "sync" it gives me the error.

有“外出提交”,但是当我“同步”时,它给了我错误。

The “Sync” button in the “Unsyched Commits”view will push and pull. This indeed requires you not to have uncommitted changes (that could be overwritten) in your working directory. Go into the “Changes” view and make a commit first if you want to keep the changes; or undo them as explained above.

“未同步提交”视图中的“同步”按钮将推拉。这确实要求您在工作目录中不要有未提交的更改(可能会被覆盖)。如果您想保留更改,请进入“更改”视图并首先提交;或按上述说明撤消它们。