问题
Let's say i have 2 remote branches, Master and Developer, and that my local repository is on the folder D:/Git_Project.
On git bash i go to the repository directory and select Master branch, i make a folder and a file inside it, commit changes, push it to remote master branch. Now i switch to the developer branch, and if i now go to D:/Git_Project with windows explorer, i can't see the folders / files from the master branch.
Now, i know that git saves those changes under the .git folder, and loads / saves them whenever we switch branches. But is it possible to have it always show both branches, each with their own folder? Basically having a "Master" and "Developer" folder under D:/Git_Project .
I know i could "cheat" and make it all in the same branch and create those folders myself, but i would lose the git branch features if i did so.
The reason i would want this is because sometimes when working on some file in the developer, or any other branch, i might want to check a particular file from another branch, and it's quite annoying to always have to switch branch just to open a file locally.
Thank you.
回答1:
Instead of placing your repo directly under D:/Git_Project, you can clone it under
D:/Git_Project/master
Then, with git worktree (with Git 2.5+), you can checkout the develop branch of that same repo in
git worktree add ../develop develop
D:/Git_Project/develop
That way, you don't need to clone twice (even shared clones are not needed here)
回答2:
The simplest solution would be to clone the repository locally - make extra directories to keep the "viewing copies" of each branch in, and just never check out different branches for those copies. git clone --local --shared /path/to/original /intended/path/to/copy
, then git checkout master
in the new one. Rinse and repeat for however many extra copies you want. You don't have to stick with just one copy to make edits in, but it would probably help from an organizational standpoint.
Since it's shared, they'll share all the actual commit records - this doesn't give you a backup of your repo, just a second place to look at it from, so don't delete a branch on one thinking that you can just get it back from the other.
See also: the docs for git clone.
来源:https://stackoverflow.com/questions/39626225/is-it-possible-to-show-all-local-branches-at-the-same-time-in-windows-explorer