Reputation: 1405
I am using Visual Studio (Professional 2019) and the Git integration there through Git Changes. I have always been using TFS, but we have decided to use Git projects on new development. I have added some stuff to the .gitignore
file, like for ignoring the .vs
folder etc. And it seems to be working as long as things are not already added in before. So far, so good.
But now we are hitting an issue where we have different changes in files like launchSettings.json
and appsettings.Development.json
files as well as the App_Data
folder.
The problem I don't understand is that we all want these files to be controlled in Git, to exist in the repo. But we want to exclude local changes form ever being pushed anywhere.
So we found information about the .git/info/exclude
file. And that's great. But it does not seem to solve the problem, because once a file is controlled, we can't exclude our own changes to that file. It only applies when the files is not controlled at all. Here's where I'm not sure at all, but it seems that way.
When we used TFS control, we were able from Visual Studio to just right-click the file and choose "Exclude" and it would appear in the "Excluded changes" list and not being checked in with the changeset.
But that's not possible in Git. At least not from Visual Studio. The only options available are Undo changes in addition to Blame (Annotate) and Stage. But we don't want to undo our changes. We just want to push our changes without including the changes.
What am I doing wrong here? Please enlighten me. I'm clearly missing something here.
Upvotes: 4
Views: 3830
Reputation: 3185
Team Foundation Version Control (TFVC) is a centralized version control system. In the meanwhile, Git is a distributed version control system. They are different version control system thus own different actions. See: Choosing the right version control for your project for details.
In TFVC repository, we could just right-click the file and choose "Exclude", then we check in all changes except that file as this thread: How to ignore files/directories in TFS for avoiding them to go to central source repository? described.
However, this action is not available in Git repository, we could follow this thread: How to stop tracking and ignore changes to a file in Git? as PWND suggested to use Git commands to implement this. Or we could use Git stage command to avoid this file to be commit as fredrik suggested, see: https://www.nobledesktop.com/learn/git/stage-commit-files for details.
In addition, you could try to set up branch policies, so code merging to master must via pull request, and then protect the target files.
Upvotes: 2