git Visual Studio 2013 Github 提交死锁
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21921515/
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
Visual Studio 2013 Github commit deadlock
提问by Walter Schultz
A few friends and I are working on a project via GitHub. We are all sharing the same branch, which may or may not be a good idea.
我和几个朋友正在通过 GitHub 开展一个项目。我们都共享同一个分支,这可能是也可能不是一个好主意。
I edited some of the code and committed the changes. I went to push commit to GitHub (I am working with Visual Studio 2013 and it's built-in Git tool), but I got this error:
我编辑了一些代码并提交了更改。我去推送提交到 GitHub(我正在使用 Visual Studio 2013 并且它是内置的 Git 工具),但是我收到了这个错误:
"There are new remote changes. You must pull them before you can push."
“有新的远程更改。你必须先拉他们才能推送。”
So I tried to pull the remote changes and I get this error:
所以我尝试拉远程更改,但出现此错误:
"An error occurred. Detailed message: An error was raised by libgit2. Category = 21 (MergeConflict). 9 uncommitted changes would be overwritten by merge"
“发生错误。详细消息:libgit2 引发错误。类别 = 21(MergeConflict)。9 个未提交的更改将被合并覆盖”
I tried to change branches so that I might be able to push my changes and then merge them with the first branch, but I got this error:
我试图更改分支,以便我可以推送我的更改,然后将它们与第一个分支合并,但出现此错误:
"Cannot switch to master because there are uncommitted changes. Commit or undo your changes before you switch branches. See the Output window for details."
“无法切换到 master,因为有未提交的更改。在切换分支之前提交或撤消更改。有关详细信息,请参阅输出窗口。”
I have no idea what to do, except possibly to email my changes to one of my friends and have them push my changes. However, I don't know what would happen with my local commits.
我不知道该怎么做,除了可能将我的更改通过电子邮件发送给我的一位朋友并让他们推送我的更改。但是,我不知道我的本地提交会发生什么。
EDIT
编辑
The problem is resolved. After making sure to sync all the commits I opened git bash and pulled the remote commits. After a few attempts I went back to Visual Studio and discovered that it had registered the merge. I resolved all of the conflicted files and was able to push the project.
问题解决了。在确保同步所有提交后,我打开 git bash 并拉取远程提交。几次尝试后,我回到 Visual Studio 并发现它已经注册了合并。我解决了所有冲突的文件,并能够推动项目。
Thanks to everyone who answered!
感谢所有回答的人!
回答by Dave Voyles
As dumb as it sounds, I just went to the command line, and it worked.
尽管听起来很愚蠢,但我只是去了命令行,它奏效了。
- Git status
- Git pull
- Git push
- Git 状态
- git pull
- git推送
all worked fine.
一切正常。
If I did that same thing within Visual Studio, it didn't work. Go figure.
如果我在 Visual Studio 中做了同样的事情,它就不起作用。去搞清楚。
回答by dmcquiggin
When using the Visual Studio Git Provider (VS 2013, VS2015), this situation can also arise in scenarios where a local Commit hasbeen performed, but, when attempting to Pull from the server and merge, the error message:
当使用Visual Studio的Git提供商(VS 2013,VS2015),这种情况也可能出现在一个本地提交的方案已被执行,但是,试图从服务器和合并,错误消息拉时:
"uncommitted changes would be overwritten by merge"
“未提交的更改将被合并覆盖”
is still displayed, and the Pull action is cancelled.
仍然显示,拉动动作被取消。
This can occur because locally, there are Untracked Filesthat were not part of the local Commit, but are part of the remote Pull; the merge resolution cannot deal with this scenario.
这可能是因为在本地,有未跟踪文件不是本地提交的一部分,而是远程拉取的一部分;合并决议无法处理这种情况。
Typicallythis occurs when some files such as T4 template outputs are included in a Commit on one workstation, but not on others.
通常,当某些文件(例如 T4 模板输出)包含在一个工作站上的 Commit 中而不包含在其他工作站上时,就会发生这种情况。
Additionally, this can occur in Visual Studio 2015, when working with MVC6projects (at time of writing), when files in the wwwroot folder have been included in a Commit on one workstation, but not on another (one possible cause of this is that the .gitignore files are different on the workstations attempting to work with the same server repository).
此外,这可能发生在Visual Studio 2015 中,当处理MVC6项目时(在撰写本文时),当 wwwroot 文件夹中的文件已包含在一个工作站上的 Commit 中,但未包含在另一个工作站上时(一个可能的原因是尝试使用相同服务器存储库的工作站上的 .gitignore 文件是不同的)。
To resolve:
解决:
a) View the Team Explorer > Changes dialogue.
a) 查看团队资源管理器 > 更改对话框。
b) Verify that any Untracked Files that actually reside in the server branch are to be included in your Commits; to do this, right-click and select Add. Alternatively, if you intend them to be overwritten, you can select Delete. Please observe caution.
b) 验证实际驻留在服务器分支中的任何未跟踪文件都将包含在您的提交中;为此,请右键单击并选择添加。或者,如果您打算覆盖它们,您可以选择删除。请注意谨慎。
c) Perform a Commit, and then a Pull, and perform any merge conflict resolution that is required.
c) 执行提交,然后执行拉取,并执行所需的任何合并冲突解决方案。
d) Perform a Push to update your Remote repository.
d) 执行推送以更新您的远程存储库。
回答by JaredPar
Right now you are trying to essentially do a git merge
with uncommited changes in your branch (pull is just fetch + merge). Git is rightfully complaining that such an operation would overwrite the uncommited changes in the branch.
现在,您正在尝试git merge
在分支中进行未提交的更改(拉取只是获取 + 合并)。Git 抱怨这样的操作会覆盖分支中未提交的更改是正确的。
To proceed with the pull operation you need to remove this uncommited changes from the working directory. There are a couple of ways to do this
要继续拉取操作,您需要从工作目录中删除此未提交的更改。有几种方法可以做到这一点
- commit them to your local repository
- stash them, run the pull operation, and then unstash them on top of the pull
- commit, fetch, rebase and then merge
- 将它们提交到您的本地存储库
- 将它们藏起来,运行拉动操作,然后在拉动的顶部取消藏匿它们
- 提交,获取,变基,然后合并
If you are new to git I would probably start with option #1.
如果您不熟悉 git,我可能会从选项 #1 开始。
回答by JJO-DEV
Visual Studio 2013 seems to be lacking maturity as a GIT UI. I ran across similar issue even after having committed all my changes locally. For errors arising from Push & Pull in Visual Studio 2013, I would recommend using Git Bash to do a git pull command. The command-line pull command is much more powerful than VS UI and will overcome some issues.
Visual Studio 2013 作为 GIT UI 似乎还不够成熟。即使在本地提交了所有更改后,我也遇到了类似的问题。对于 Visual Studio 2013 中 Push & Pull 引起的错误,我建议使用 Git Bash 执行 git pull 命令。命令行 pull 命令比 VS UI 强大得多,并且会克服一些问题。
In response to Walter Schultz, you are getting the error because you seem to be trying to keep binary & assembly files (dll and exe's) in version control. Binary files are not editable & not mergeable, thus they should not be included in version control.
作为对 Walter Schultz 的回应,您收到错误是因为您似乎试图将二进制和程序集文件(dll 和 exe)保留在版本控制中。二进制文件不可编辑且不可合并,因此它们不应包含在版本控制中。
In order to exclude these files from the GIT repository, you can create a .gitignore file and include following items:
为了从 GIT 存储库中排除这些文件,您可以创建一个 .gitignore 文件并包含以下项目:
--- begin .gitignore file ----------------
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
*.cache
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
x64/
build/
bld/
[Bb]in/
[Oo]bj/
Dev/
bin/
--- end gitignore file ----------------
Once you create the .gitignore file, go into your local repository and delete all files in your /Bin/ folder and other files that you do not wish to keep track of.
Then push to local & sync your code to server repository.
Hope this helps.
创建 .gitignore 文件后,进入本地存储库并删除 /Bin/ 文件夹中的所有文件以及您不想跟踪的其他文件。
然后推送到本地并将您的代码同步到服务器存储库。
希望这可以帮助。
回答by RYUX123
Same thing was happening to me, I committed all my changes and get the same error when I try to switch branches.
同样的事情发生在我身上,我提交了所有更改,并在尝试切换分支时遇到了同样的错误。
I realized there was one file I chose to "ignore" which I left under the "Excluded Changes". Apparently, VS2013 is not properly handling this exclusions well.
我意识到有一个我选择“忽略”的文件,我把它留在了“排除的更改”下。显然,VS2013 没有很好地处理这个排除。
So after many tries I came up with a simple solution:
所以经过多次尝试,我想出了一个简单的解决方案:
- I moved the file to ignore from "Excluded Changes" to the "Included Changes";
- I made a local commit;
- Switched branch without problem;
- 我将要忽略的文件从“排除的更改”移至“包含的更改”;
- 我做了一个本地提交;
- 切换分支没有问题;
回答by Ibrahim ben Salah
I didn't had uncommit changes, still had the same error when performing the merge to develop. I tried:
我没有未提交的更改,在执行合并开发时仍然出现相同的错误。我试过:
- git status, and then
- git pull
- git 状态,然后
- 拉
And then tried the merge to develop again and the error does not show up anymore. I had to solve some conflicts though. I can image that only the second command is really relevant but I have no clue what is happening here so I rather document all the steps.
然后尝试合并再次开发,错误不再出现。我不得不解决一些冲突。我可以想象只有第二个命令是真正相关的,但我不知道这里发生了什么,所以我宁愿记录所有步骤。
回答by JohnOpincar
I was having this problem in VS 2015 and the only thing that fixed it was restarting VS. None of the other situations mentioned above were applicable.
我在 VS 2015 中遇到了这个问题,唯一修复它的是重新启动 VS。上述其他情况均不适用。
回答by cal5barton
I had to download the command line tools and it allowed me to checkout the master branch there (Which also checked it out in VS). I then did a git pull which then brought up additional errors due to conflicts with the merge of the remote and local branches. Fixed the conflicts, committed, and then synced which solved this problem.
我必须下载命令行工具,它允许我在那里检出 master 分支(也在 VS 中检出)。然后我做了一个 git pull ,然后由于与远程和本地分支的合并冲突而带来了额外的错误。修复了冲突,提交,然后同步解决了这个问题。
回答by faldeland
Running this from command line "git merge {branch name}", yielded a more specific error. "Merge conflict in .gitignore"
从命令行“git merge {branch name}”运行它,产生了一个更具体的错误。“合并 .gitignore 中的冲突”
回答by Sagar Jha
I had a similar issue for a new MVC project I created and for any new branch on merge it gives an error which I don't have a project I created a month ago. I added the .gitattribute file from the nice working project to the project with the error mentioned above and it fixed the issue. Now I am able to merge without any issue.
对于我创建的新 MVC 项目和合并时的任何新分支,我遇到了类似的问题,它给出了一个错误,我没有一个月前创建的项目。我将 .gitattribute 文件从不错的工作项目添加到带有上述错误的项目中,并解决了该问题。现在我可以毫无问题地合并了。
I simply added the .gitignore to the master and commit it.
我只是将 .gitignore 添加到 master 并提交。