可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I've setup a GIT repository for a VS 2013 solution on visualstudio.com. The repository worked great while I was becoming accustomed to using TFS (in GIT mode).
Then I decided to familiarize myself with Branches, so I created a branch off of the master. I've made quite a few changes in this branch. I've committed the changes over time and have performed a Sync to push my local commits to the visualstudio.com repository. This all works.
The problem I am having is that I somehow lost the ability of switching back to the master branch. I cannot merge my newly created branch into the master. Every time I try to do anything that involves the master I get the following error in VS:
Cannot switch to master because there are uncommitted changes. Commit or undo your changes before you switch branches. See the Output window for details.
The Output window never contains any 'details'...
What "uncommitted changes" does this message refer to? Since I cannot get into the master branch I have no way of committing any of its changes (nor am I sure that I want to?). And the current (only other) branch I am in has been committed and sync'ed.
I'm really just learning TFS, GIT and source control. How do I safely recover from this problem?
回答1:
Okay, I had the same issue myself as rwkiii - this is a bug in Visual studio and is not an easy one to fix. Here are the symptoms:
Visual Studio states that you cannot merge/switch braches/etc. because you have uncommitted changes - which is fine, except all your changes have been committed.
Cannot switch to master because there are uncommitted changes. Commit or undo your changes before you switch branches. See the Output window for details.
Here's a screenshot to be clearer.
If you look at the output window, it may appear empty but you have to change "Show output from" to "Source Control - Git". This will list the file that Visual Studio thinks has changes.
Now, things that I tried that didn't fix it (so you don't have to):
- Restarting Visual Studio
- Restarting the machine
- Switching Projects
- Using external git tools (All of which said "no changes")
- git reset
- Making arbitrary changes to the file and committing that. Commits ok, VS still thinks there's more changes
In the end, I had to go and delete the file from the disk, then "undo" that change from the Team Explorer window:
Not the most ideal solution, but it does seem to fix it.
回答2:
I used the git command prompt to resolve the issue. I can't guarantee that it's the best way or the only way, but it worked for me in Visual Studio 2013.
Under Changes in the Team Explorer, choose Open Command Prompt.
In the command prompt type:
git status
It will list the files that are open for change.
Copy off those files (just in case), then you can then discard the changes in the working directory in the command prompt.
git checkout -- mysubdir\myfile.ext
Don't attempt to change branches in Visual Studio, it still won't work!
Instead at the command prompt switch to the branch in question.
git checkout branchname
When you go back to Visual Studio it will prompt you to reload the project. After that the branch will be updated correctly to the branch you chose from the command line.
hth
回答3:
I resolved a similar issue without having to delete a file or make new changes.
After committing changes on BranchA, merging with Master and pushing via Git bash, the next time I opened the project in VS and looked at Team Explorer, it showed that there were changes on the Master branch. No changes showed up when checking status via Git bash, but 10 files were listed in VS Output. Diffs on all files showed no changes. I tried a commit amend at this point, but it wouldn't let me amend the previous commit (see more about this below, since ultimately this will fix my issue).
Tried to switch to BranchA in VS and got the message that I can't switch due to uncommitted changes. Switch to BranchA via Git bash, and status shows no changes. Refresh VS Team Explorer so it is now on BranchA, shows 14 file changes, even more than Master, but again, diffs on all files showed no changes.
While on BranchA in Team Explorer, I clicked on Actions->Amend Previous Commit. This time it let it happen and all the changes were cleared. It then showed a pending commit, but checking status on Git bash showed nothing pending, so going to Home in Team Explorer and coming back, cleared the pending commit message.
Switched to Master in Team Explorer, no more changes showing there either. All is well.
回答4:
Uncommited changes means that you have modified one or more files which have already been added to git and those changes have not been "saved" in a commit or in your git stash.
When you switch between branches you are not allowed to have uncommited changes (new files that have not been added to git are fine though) as changes in other branches might overwrite your uncommited changes.
I'm unfamiliar with how Visual Studio integrates with git as I myself use PoshGit with Powershell
The way to proceed is to:
- Undo your changes
- Commit your changes
- Or stash your changes (see the Interrupted workflow section).
回答5:
Hi this did the trick for me...
Try using the command prompt
Team Explorer > Unsynced commit > Actions > Open Command Prompt
Do a git checkout branchName
回答6:
I've noticed a few times sln items are marked as changed but don't appear that way in Solution Explorer. What I have done as others suggested is in command prompt,
git status (this should show you culprit files)
then add the individual files. Or what I personally do is run:
git add -A
which will add all changed files to view nicely in Team Explorer, where you can undo/delete as you want. Haven't had a problem with this approach.
回答7:
We regularly run into this issue, because we have a particular file which must always be excluded from changes, but sometime gets changed.
What works for us when the error message appears is:
- In VS look in the Output window to see which file is causing the issue.
- In Git bash run
git update-index --no-assume-unchanged TheNameOfTheFileCausingTheIssue
- In VS Undo Checkout on this file
- In VS change the branch in Manage Branches.
This may or may not work for your situation, but I have added it in case it puts someone in the right direction. Please be sure you understand the git command before running it!
回答8:
I ended up solving my issue by deleting my repo from within File Explorer and then from within Visual Studio selecting "undo all changes" when the deletions registered to be committed. Upon restoring the repo Visual Studio functioned as expected in tandem with git.
回答9:
The problem is that sometimes after pull path to some files do not match their equivalent in repository database because comparison is case-sensetive.
For example, you could have "MyLibrary\ABC\Folder\MyFile.cs" in repository but "MyLibrary\Abc\Folder\MyFile.cs" on the disk. There will be no changes detected in "git status" but Visual Studio will block branch switch.
Deleting just MyFile.cs from disk in that case will not solve the problem - you'll need to delete ABC directory and then undo changes for Visual Studio to recreate folder structure with correct names.
回答10:
I had this issue after changing a filename from starting with a lower case letter to an upper case letter after I'd already committed the file. I fixed it by changing the name of the file (I just added a '1' on the end) and then committing that change. I was then able to switch branches.
As mentioned above, I had to change the 'Show output from:' combo to 'Source Control - Git' in the Output window in order to see the name of the offending file, that then showed me that the file name VS/git was expecting wasn't capitalised, where as the name in the solution explorer/on the file system was capitalised.
回答11:
One thing that worked for me is :-
1) Right click on branch you want to checkout.
2) Click on the Reset option.
3) Click on the Delete Changes (--hard)
4) Right click on the branch and select checkout
回答12:
1: Open git bash
2: Point to your git repository
3: check you branch status by using command "git status
"
if you have any re usability of your changes for other branch then use "git stash save
",
(this will save your changes locally,you may face some conflict error, you can ignore
for now) if you see any un-merged file in git status result and you want to keep the changes use "git add <file path>
"
4: once your local changes are saved use command "git reset --merge
"
this will reset your local branch to the original checkout, now you are ready to switch
the branch you may see the conflict files in visual studio Team Explorer>changes,
if you don't want to keep that file changes right click and select undo changes or use
"git add <file path >
" to add this file with other saved files.
5: Now your git branch is ready for switch, type "git checkout <branch path>
"
6: to pop saved changes use "git stash pop
", this will merge the saved changes in you current branch.
回答13:
i faced same problem then i noticed the uncommitted changes are from different project. once i committed those changes, it allowed me branch change.