1

I'm working in Visual Studios with TFS and I have 3 branches. In our repo each branch has 2 solutions with configs files. Those config files have been committed and need to remain committed. However, on my machine I need to change the config files to point to the correct db.

I've tried git update-index --skip-worktree App.config however when I go to switch branches I get the error message below:

Output from visual studios

Also with

git rm --cached App.config

it creates the .gitignore file and when that is commited the App.config is removed from the repo which I don't want.

My goal is to just ignore the changes I make to the file but keep the file in the online git repo.

Community
  • 1
  • 1
DevEng
  • 1,114
  • 2
  • 15
  • 29
  • Which branch is checked out on your local machine? What visual Studio are you using? Also, do you use a GUI like GitExtensions? – BikerDude Aug 15 '17 at 18:18
  • They all have been checked out. VS 2017 allows me to switch between them with a dropdown and it automatically updates the files on my local machine. I have TortoiseGit as a GUI but I'm only using VS right now – DevEng Aug 15 '17 at 18:27
  • Oh awesome. So, just as a clarification, the file you select from the dropdown is the only one that has been checked out, rest of them exist locally, but have not been checked out. Any change you make to any of these branches, would not be pushed online automatically. – BikerDude Aug 15 '17 at 18:30
  • The dropdown is used to switch branches, nothing to do with individual files. All of the files exist on the repo and have been checked out, so any change I make to my local files will be different from the repo so visual studio wants me to stage them. So I can't change branches, and doing either of the commands above gives the same error. – DevEng Aug 15 '17 at 19:35
  • I think you are confused, that dropdown is the actual thing which checks out one of the the different branches onto your disk, only one at a time. Refer to this [link](https://stackoverflow.com/questions/15296473/what-do-git-checkouts-really-mean) – BikerDude Aug 15 '17 at 19:45
  • I really miss the "exclude" and "include" options on a controlled file in TFS. Easier to click in a GUI than write commands. Any idea if this is something Microsoft will implement to the Git Changes plugin in Visual Studio at some point? – Mats Magnem May 04 '21 at 08:02

2 Answers2

0

git update-index --skip-worktree only hides the changes from being shown in the index, it doesn't make the changes disappear. If you are switching branches git needs to be able to update your config file, but your local changes prevent it from doing so (which is true whether or not the file is hidden from the index).

This is a workflow I have been using lately:

  1. Create a branch for local testing commits only. I'll call it test. Commit your config changes there.
  2. Do your work on a local branch as normal. I'll call it work. Commit small changes as you go (which is good practice anyway).
  3. When you need to run tests with your updated config file, checkout test and rebase it on top of work. (If you are doing this a lot you can set test to track work to save some keystrokes.)
  4. Once test is on top of work, you can git checkout test to use your modified configs, or git checkout work to resume coding.
  5. When you are ready to publish your changes, rebase --interactive to squash all of your temp commits into one (or more) official change(s). Push from work, and leave test alone until you need those local changes again.
0x5453
  • 12,753
  • 1
  • 32
  • 61
0

I'd suggest the following approach. Let Git know about the changes:

git update-index --no-skip-worktree EACH_CONFIG_FILE 

Stash those changes:

git stash save "Save local conf"

You can now checkout to the other branch without problems, then restore your local changes:

git stash pop

and you can fix the conflicts, if any, accepting your local config files. Finally, update index again to skip those files.

saccodd
  • 972
  • 9
  • 23