在本地网络上使用Git。从一个存储库克隆到多个用户,推回到远程并能够看到来自所有克隆的更新 [英] Using Git on a local network. Cloning from one repository to multiple users, pushing back to remote and being able to see updates from all clones
问题描述
我在本地(和其他地方)搜索了一些关于在本地(lan)网络上使用git的帖子,但是我错过了一些东西,或者它只是不起作用。我的方案如下:
- 我们在所有用户PC上共享一个项目(Z:/)网络驱动器
- 我想在共享驱动器的目录'x'中创建一个存储库
- 每个用户(其中4个)需要克隆存储库
这个看起来很简单,而且用户可以进行更改,提交并推送到远程主存储库我访问过的所有网站上的一般步骤是:
-
在远程机器上创建裸仓库,在这种情况下为
Z:/ SOME_FOLDER
在Z:/ SOME_FOLDER / master中的远程仓库中创建一个仓库,添加文件,提交并推送
这很好,但是如果我将Z:/ SOME_FOLDER上的远程仓库克隆到pc#3上,请进行一些更改,提交和推送,当我在PC#2上执行 git status
时,它并不告诉我在远程存储库中存在修改过的文件(尽管我认为这只是检查本地版本库),并且有修改过的文件,因为PC#3推送发生了变化。
我可以运行一个像 git fetch file:// z :/ SOME_FOLDER / master
它会更新,但我的问题是这样的:
我们如何在Z:/ SOME_FOLDER我们都可以(我们4个)克隆,提交和推送更改,但也可以看到那些已被其他用户修改的远程文件?这是毫无意义的运行获取命令,而实际上并不知道已经改变了什么。
我是git新手,因为他们来了,所以也许我错过了一个关键的步骤。任何指导或资源链接将不胜感激。我已经看过的资源:
编辑2012-02-14 13h30 $ b
通过使用David的建议来使用 git pull
而不是 git fetch
,我们能够使用其他用户推送的主服务器中的更改更新了本地存储库。我们目前面临的最大挑战是,如果我们其中一个人回复到之前的提交,例如: git reset --hard SOME_HASH
它不允许我们推送它因为它是一个非快进的提交。
即使被恢复的人运行git pull(我通过合并更改),他的文件再次更新裸仓库中的最新版本。我们如何获得一个本地存储库,该存储库已恢复为先前的提交到远程服务器,以便我们可以在运行pull命令时恢复所有服务? 方案
我们如何在Z:/ SOME_FOLDER上拥有一个中央存储库,我们都可以(我们4个)克隆,提交和推送更改,但也可以看到这些远程文件已被其他用户修改过? c $ c>命令将获得远程存储库中的更改并将其存储在本地存储库中(在远程分支中),但不会将它们合并到当前/活动分支。如果你想看到远程仓库的分支存储在本地仓库中,你可以使用 / code>
所有以
remotes /
开头的分行都来自远程仓库。 p>
要查看这些分支中的更改,可以使用
git log
指定分支名称,例如git log remotes / origin / master
并且查看已更改的文件(与本地版本相比),您可以使用
git diff - -stat remotes / origin / master
另外,您还可以使用
gitk - -all
来直观地检查不同分支中的更改。
仅限于
git status
命令检查活动存储库中的更改(未提交的更改)。所以它不会比较你现在与其他分支。
就个人而言,我通常使用
git fetch
,而不指定该分支将检索远程存储库中的所有分支。然后我使用gitk --all
来直观地检查对远程存储库所做的更改。在此之后,我可以决定如何处理我自己的更改(重新整合,合并,樱桃选择等)。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
EDIT 2012-02-14 13h30
By using David's suggestion to use
git pull
rather thangit 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?
解决方案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 usegit 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 usegitk --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).这篇关于在本地网络上使用Git。从一个存储库克隆到多个用户,推回到远程并能够看到来自所有克隆的更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!