问题
I've used Git with Visual Studio for about 9 months, and have searched online for how to do this but still haven't found this problem addressed. Maybe I've been searching with the wrong keywords.
By "work spaces", I am referring to the developer's environment of tabs, windows, breakpoints and bookmarks within Visual Studio that a user might set during the time (s)he works on a story. I am not referring to Visual Studio Code's project-less environment, but Visual Studio's project-based environment.
Scenario: Developers have to switch back and forth between areas of a large project to apply features and bug fixes without a way to automatically switch to that work's related "work spaces": tabs, windows, breakpoints and bookmarks related to that feature/bug.
Steps:
- The developer creates a new branch from either a local master branch copy or directly from the online master branch.
- In the process of adding the feature or applying a fix, the developer navigates to the appropriate files and sets up their "work space" with files related to that area of code being added or changed.
- As soon as the fix is committed and pushed up to be peer-reviewed, the developer moves onto the next story, creating a new branch from master, as before.
- If there is a suggestion or an issue with the code during peer review, the developer must stop whatever work they're doing (either commit or stash their work locally) and switch back to that branch to address or research the issue.
- When the developer does so, none of the open files, the separated windows, bookmarks or breakpoints change to how it was when they checked in their work.
- Once the developer has fixed/addressed the issue, they switch back to the work they were interrupted from by popping the stash or pulling in their local commit.
- Again, none of the related open files, separate windows, bookmarks, etc. are restored.
It wouldn't make sense to push the .suo or .user files, as not everyone is working on the same code, or view code the same way (what the developer determines should be seen in a new window or just in a tab). But I was thinking it might make sense to check in these files locally and not push them to the server.
Is there an easy way to do this with git? To commit private files that don't get pushed up to the server - like an ignore filter? If not, is there a plug-in or a tool that can be used to achieve the results I'm looking for?
Thank you.
回答1:
Whether the user must "immediately" interrupt what they're doing to address review comments is a matter of team dynamics[1].
I guess I'll suggest a couple hacks - because there aren't any good technical solutions to the problem as you present it - but my real recommendation is: don't[2].
But ok... the easiest solution for a developer who finds this to be a problem is likely to use multiple worktrees. When a task has been submitted for review, instead of checking out the branch for the next task into the current worktree, you can add a new one and work there. https://git-scm.com/docs/git-worktree
Or if you're not comfortable with multiple worktrees, you could even create another clone of the repo - though it's then possible to create a divergent history.
The "next best" solution involves creating a local repo for your local workspace files, and making the actual code repo a submodule. There's a lot of complexity there, so I don't recommend it and won't go into a lot of detail about how you'd do it; but for completeness' sake, I'll mention that it could be done.
[1] If indeed that is the expectation, I'd suggest that there are bigger problems that are not technical in nature. The fact is that even with a solution that re-opens your files where you left off, there is a mental load involved in task switching.
[2] The question poses the wrong problem. Getting files loaded is the smallest part of the context switch cost. You can use git to quickly re-establish what files you were working on (diff your branch against the merge base using --name-only
). You can use the IDE to quickly navigate to the relevant files.
That's why you aren't finding anything by googling. IT's not the wrong keywords - it's that most developers wouldn't even think of a need for the feature you're after
回答2:
I try to solve the problem of switching back and forth between areas of a large project with my Task Canvas extension.
Switching a task in Task Canvas automatically restores tabs, code fragments, notes, startup projects and the Git branch. Saving windows, breakpoints and bookmarks is not yet implemented.
来源:https://stackoverflow.com/questions/58397696/how-should-i-use-git-with-visual-studio-to-store-work-spaces-without-pushing-the