问题
I have searched a few posts here (and elsewhere) about using git on a local (lan) network, but either I am missing something, or it's just not working. My scenario is as follows:
- We have a shared network drive of projects (Z:/) on all users PC's
- I want to create a repository within directory 'x' on the shared drive
- Each user (4 of them) need to clone the repository
- Users make changes, commit and push to remote master repository when major changes are made
This seems simple enough, and the general steps on all sites I visited were:
Create a bare repository on remote machine, in this case Z:/SOME_FOLDER
Create a repository on one local machine, add files, commit and push to remote repository in Z:/SOME_FOLDER/ master
Clone the remote repository at Z:/SOME_FOLDER onto a local PC (let's ASSUME PC #2)
This works perfectly, however if I clone the remote repository at Z:/SOME_FOLDER onto pc #3, make some changes, commit and push, when I perform git status
on pc #2 it is not telling me that there are modified files in the remote repository (although I assume this is only checking the local repository), and there are modified files because PC #3 pushed changes up.
I can run a command like git fetch file://z:/SOME_FOLDER/ master
and it will update, but my question is this:
How can we have a central repository on Z:/SOME_FOLDER that we can all (4 of us) clone from, commit and push changes, but ALSO see those remote files that have been modified by another user? It is pointless running a fetch command without actually knowing what has been changed.
I am as much of a git novice as they come, so perhaps I have missed a crucial step. Any guidance or links to resources will be much appreciated. Resources I have already looked at:
https://serverfault.com/questions/65104/git-repository-over-lan
http://blog.lazyhacker.com/2010/04/setting-up-git-for-home-network.html
http://www.google.co.za/url?sa=t&rct=j&q=how%20to%20use%20git%20on%20a%20local%20network%3F&source=web&cd=1&ved=0CCMQFjAA&url=http%3A%2F%2Fstackoverflow.com%2Fquestions%2F2230500%2Fgit-on-a-windows-lan&ei=mxQ6T4eBBIaxhAev_Kz-CQ&usg=AFQjCNEoeBR-kqddSODhHkDlf2qpC8o4tw
EDIT 2012-02-14 13h30
By using David's suggestion to use git pull
rather than git fetch
, we are able to updated our local repositories with the changes in the master that other users have pushed. The biggest challenge that we are facing at the moment is that if one of us reverts to a previous commit eg: git reset --hard SOME_HASH
it does not allow us to push it due to the fact that it is a non fast-forward commit.
Even when the person who reverted runs git pull (which I though merges the changes) his files are again updated the latest version on the bare repository. How would we get a local repository that was reverted to a previous commit to be pushed to the remote so we can all be reverted when we run a pull command?
回答1:
How can we have a central repository on Z:/SOME_FOLDER that we can all (4 of us) clone from, commit and push changes, but ALSO see those remote files that have been modified by another user? It is pointless running a fetch command without actually knowing what has been changed.
The git fetch
command will get changes in the remote repository and store it in the local repository (in "remote" branches) but not merge them to the current/active branch. If you want to see branches from remote repositories stored your local repository, you can use
git branch -a
all branches started with remotes/
are from remote repositories.
To see changes in those branches, you can use git log
with specifying the branch name, e.g.
git log remotes/origin/master
and to see files that are changed (compared to your local version), you can use
git diff --stat remotes/origin/master
Additionally, you can also use gitk --all
to visually inspect changes in different branches.
The git status
command only check changes in the active repository (uncommited changes). So it will not compare what you currently have with other branches.
Personally, I usually use git fetch
without specifying the branch so all branches in the remote repository will be retrieved. Then I use gitk --all
to visually inspect what changes have been made to the remote repository. After this I can decide what to do with my own changes (rebase, merge, cherry-pick, etc).
来源:https://stackoverflow.com/questions/9274995/using-git-on-a-local-network-cloning-from-one-repository-to-multiple-users-pus