Visual Studio 2013 Github commit deadlock

匿名 (未验证) 提交于 2019-12-03 02:47:02

问题:

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.

I edited some of the code and committed the changes. I went to pusj commit to github (I am working with Vis. Studio 2013 and it's built-in Git tool), but I got this error:

"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"

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."

I have no idea what to do, except possibly to email my changes to one of my friends and have them push my changes. But 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.

Thanks to everyone who answered!

回答1:

As dumb as it sounds, I just went to the command line, and it worked.

  1. Git status
  2. Git pull
  3. Git push

all worked fine.

If I did that same thing within Visual Studio, it didn't work. Go figure.



回答2:

When using the Visual Studio Git Provider (VS 2013, VS2015), this situation can also arise in scenarios where a local Commit has been performed, but, when attempting to Pull from the server and merge, the error message:

"uncommitted changes would be overwritten by merge"

is still displayed, and the Pull action is cancelled.

This can occur because locally, there are Untracked Files that were not part of the local Commit, but are part of the remote Pull; the merge resolution cannot deal with this scenario.

Typically this occurs when some files such as T4 template outputs are included in a Commit on one workstation, but not on others.

Additionally, this can occur in Visual Studio 2015, when working with MVC6 projects (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).

To resolve:

a) View the Team Explorer > Changes dialogue.

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.

c) Perform a Commit, and then a Pull, and perform any merge conflict resolution that is required.

d) Perform a Push to update your Remote repository.



回答3:

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.

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

  1. commit them to your local repository
  2. stash them, run the pull operation, and then unstash them on top of the pull
  3. commit, fetch, rebase and then merge

If you are new to git I would probably start with option #1.



回答4:

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.

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.

In order to exclude these files from the GIT repository, you can create a .gitignore file and include following items:

--- 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.



回答5:

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.

So after many tries I came up with a simple solution:

  1. I moved the file to ignore from "Excluded Changes" to the "Included Changes";
  2. I made a local commit;
  3. Switched branch without problem;


回答6:

I didn't had uncommit changes, still had the same error when performing the merge to develop. I tried:

  1. git status, and then
  2. git pull

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.



回答7:

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.

http://blogs.msdn.com/b/visualstudioalm/archive/2013/03/08/use-the-git-command-prompt-to-supplement-visual-studio.aspx



回答8:

Running this from command line "git merge {branch name}", yielded a more specific error. "Merge conflict in .gitignore"



回答9:

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.

I simply added the .gitignore to the master and commit it.



回答10:

I had to run git add-in in VS 2013 without solution loaded.

My problem was that VS started application.vshost.exe when loaded windows application project, and hence blocked git add-in to perform some operations.

Already used .gitignore from VS studio template, but that is something different.



回答11:

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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!