Frage

I'm using Visual Studio 2013 Express using Git on a project.

I created my repository and copied the project files into it from another directory. I then checked my .gitignore and .gitattributes files. .gitignore was pre-configured and looked to cover everything I needed to ignore for commits at this point.

I selected the Changes tab in Visual Studio under the "Team Explorer" tab and saw all my files were untracked, as expected. I then clicked "Add All". I assumed VS would only add files not matching those in my .gitignore to the "Included Changes" list. Instead, all the files were added to the "Included Changes" list.

I then thought that maybe the .gitignore file would be used when committing and that only files not matching those in .gitignore would be committed. So I added a commit message and clicked "Commit".

When I select "View History" from the "Actions" drop down in the "Changes" tab I am presented with a pane to the left of my "Team Explorer" view that shows all the commits I've made. There is only 1 commit. When I double click that commit, the "Team Explorer" tab displays Commit 8db34b1c and all the files in my project are listed there in the tree view with [add] after their name.

For example, App_Data/Movies.mdf and App_Data/Movies.ldf are listed even though my .gitignore includes the lines

# SQL Server files
App_Data/*.mdf
App_Data/*.ldf

I don't understand how the .gitignore file is being used here or what the "Included Changes", "Excluded Changes" or "Untracked Files" sections mean.

An explanation of the above behavior and sections would be appreciated.

Edit--

I deleted my .git directory, created a new repo, copied my project files in again and then took screenshots of what I see.

Here are images of my .gitignore file and my "Changes" tab.

enter image description here enter image description here

There's this SO question and this msdn question which shows that other people seem to be having issues as well. I tried deleting the .xml file added by VS in my .git directory (as noted in the msdn question) but that did not solve the issue for me.

Edit 2 --

This is my current directory structure :

/MvcMovie/
    |--.git/
    |
    |---MvcMovie/
    |       |--App_Data/
    |       |     |--Movies.mdf
    |       |     |--Movies.ldf
    |       |     
    |       |--App_Start/
    |       |--etc...
    |
    |--packages/
    |--.gitignore
    |--.gitattributes
    |--MvcMovie.sln
    |MvcMovie.v12.suo
War es hilfreich?

Lösung

@dustinmoris is right in his answer, but the fix is not as immediately obvious as the procedure would lead you to believe. So let me explicitly walk you through the process to make sure the files in your .gitignore file are obeyed by Visual Studio.

1. Create Your Solution & Add It To Source Control Visual Studio 2013 Solution Creation

I created a sample MVVM Light XAML Solution and you can see that all the currently untracked files that should ideally be added to the next commit show up with a little green plus next to their icons.

Solution directory listing

The problem is that the MvvmLight.Win81_TemporaryKey.pfx file is listed to be added even though all files of type .pfx are explicitly called out to be ignored in my .gitignore.

gitignore

This is even more obvious if I select the solution in the Team Explorer panel and then select the Changes button. I see a list of all files pending inclusion on the next commit.

Team Explorer Changes

This list contains every file in the Solution, not just the subset specified by the .gitignore file.

2. Close Visual Studio & Delete the ms-persist.xml File

It's in a hidden directory so it's kind of hard to find. It should be located at the following path

Solution Directory\.git\ms-persist.xml

ms-persist.xml file

3. Re-Open The Solution and Commit Files

You'll notice that it appears as if your solution is no longer under source control because all the icons have lost their green plus signs, but don't worry it's fine.

Solution directory listing after deleting ms-persist.xml

Head on over to the Team Explorer panel and then select the Changes button. Again, you'll see that the project is still being tracked by source control, as well as a list of all files to be added on the next commit. More importantly, you'll notice that your .gitignore list was properly adhered to this time and all files specified as ignored are no longer listed as pending changes to be added to the next commit. As you can see below, the MvvmLight.Win81_TemporaryKey.pfx file is no longer scheduled for the next commit!

Corrected commit changes

Hope that helps someone. After all that hassle here is my honest advice:

Learn and use the command line interface since it provides the full range of functionality git offers and has the same interface on all platforms.

Andere Tipps

If anyone ever wonders how to fix it. This is the solution: Go to your .git folder (might be hidden) and open up the ms-persist.xml and you can see the tracked files, excluded items, etc.

Just manually fix what VS has messed up and restart the IDE and you should be good again!

Don't delete the whole .git folder like it is often mentioned on other SO threads!

Thanks to Eric Nelson's blog post: https://ericnelson.wordpress.com/2014/06/21/is-visual-studio-2013-ignoring-your-gitignore-file/

AppData/*.mdf and AppData/*.ldf refer to .mdf and .ldf files that exist in the AppData directory that is in the root of your git repository.

Your AppData directory actually exists beneath the MvcMovie directory. You can add:

MvcMovie/AppData/*.mdf
MvcMovie/AppData/*.ldf`

to your .gitignore to ignore those specific files, or, if you want to ignore the .mdf and .ldf directories in all AppData folders throughout your repository:

**/AppData/*.mdf
**/Appdata/*.ldf

If you change the SQL database file specifications in the .gitignore to:

# SQL Server files
*.mdf
*.ldf

Wouldn't that ignore all SQL database files throughout the entire solution folder tree, no matter what subfolder it was found in?

  1. In Team Explorer, go to your solution and then to the changes view.
  2. Select the silly files you want to exclude.
  3. Right click and select Ignore this extension. Team Explorer - Ignore this extension
  4. You will see that there have been changes made to the .gitignore which you can now commit.

.gitignore

*.ldf
*.mdf

Or you can use the Ignore this local item to only ignore that specific item if you don't want to ignore an extension completely.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top