2016-08-05 1 views
-1

でリポジトリを共有する場合、 を用いる必要:I共有する2つの方法を試みた「INIT --bare」リポジトリを共有し、異なるメンバーと同じプロジェクトを開発するためにGitの

(方法1) Githubでリポジトリを作成し、ローカルコンピュータにその特定のリポジトリをクローンするようにメンバーに依頼します。

(方法2) "--bare"で初期化し、作成したGithubリポジトリパスと同じリモートパスを設定します。 メンバーにGithubリポジトリをクローンするよう依頼します。

どちらの方法でも、pull/add/commit/pushコマンドを正しく実行できます。 つまり、リポジトリはメンバーに共有されます。

こうすることで、Gitでリポジトリを共有するときに "init --bare"コマンドを使用しなくても共有リポジトリを作成できるようになったので混乱しました。 。

"init --bare"がリポジトリを共有するために集められている情報がたくさん集まっているので、 私の質問は、 "裸のコマンドを使わずに共有リポジトリを作成できるのですが、 -bare "?

もし私が間違っていたり、もっと良い提案があれば教えてください。

ありがとうございました。

2016年8月9日を追加しました:[INIT]ケースの一つとケース2 [INIT --bare]:

私は2つの実験を行いました。

私は同じ方法で共有リポジトリを作成しようとしましたが、 ケース1 [init]で失敗したようです。

----------------Case One [init]---------------- 
(create shared_repo) 
[/home/huang]$ mkdir git_repo_shared 
[/home/huang/git_repo_shared]$ cd git_repo_shared 
[/home/huang/git_repo_shared]$ git init 
Initialized empty Git repository in /home/huang/git_repo_shared/.git/ 

(User 1) 
[/home/huang/git_repo_shared]$ cd .. 
[/home/huang]$ mkdir User1 
[/home/huang]$ cd User1 
[/home/huang/User1]$ git clone /home/huang/git_repo_shared 
Initialized empty Git repository in /home/huang/User1/git_repo_shared/.git/ 
warning: You appear to have cloned an empty repository. 

(User 2) 
[/home/huang/User1]$ cd .. 
[/home/huang]$ mkdir User2 
[/home/huang]$ cd User2 
[/home/huang/User2]$ git clone /home/huang/git_repo_shared 
Initialized empty Git repository in /home/huang/User2/git_repo_shared/.git/ 
warning: You appear to have cloned an empty repository. 

(The revision made by User1 can syncronize to User2's folder) 
[/home/huang/User2]$ cd ~/User1/git_repo_shared 
[/home/huang/User1/git_repo_shared]$ echo test_user1 > test_user1.txt 
[/home/huang/User1/git_repo_shared]$ git add test_user1.txt 


[/home/huang/User1/git_repo_shared]$ git commit -m "test_user1.txt" 
[master (root-commit) ae09328] test_user1.txt 
Committer: huang <[email protected]> 
Your name and email address were configured automatically based 
on your username and hostname. Please check that they are accurate. 
You can suppress this message by setting them explicitly: 

    git config --global user.name "Your Name" 
    git config --global user.email [email protected] 

If the identity used for this commit is wrong, you can fix it with: 

    git commit --amend --author='Your Name <[email protected]>' 

1 files changed, 1 insertions(+), 0 deletions(-) 
create mode 100644 test_user1.txt 


[/home/huang/User1/git_repo_shared]$ git push origin master 
Counting objects: 3, done. 
Writing objects: 100% (3/3), 244 bytes, done. 
Total 3 (delta 0), reused 0 (delta 0) 
Unpacking objects: 100% (3/3), done. 
remote: error: refusing to update checked out branch: refs/heads/master 
remote: error: By default, updating the current branch in a non-bare repository 
remote: error: is denied, because it will make the index and work tree inconsistent 
remote: error: with what you pushed, and will require 'git reset --hard' to match 
remote: error: the work tree to HEAD. 
remote: error: 
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to 
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into 
remote: error: its current branch; however, this is not recommended unless you 
remote: error: arranged to update its work tree to match what you pushed in some 
remote: error: other way. 
remote: error: 
remote: error: To squelch this message and still keep the default behaviour, set 
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'. 
To /home/huang/git_repo_shared 
! [remote rejected] master -> master (branch is currently checked out) 
error: failed to push some refs to '/home/huang/git_repo_shared' 

$ cd ~/User2/git_repo_shared/ 
$ git pull origin master 
$ ls 


----------------Case Two [init --bare]---------------- 
(create shared_repo) 
[/home/huang]$ mkdir git_repo_shared_bare 
[/home/huang]$ cd git_repo_shared_bare 
[/home/huang/git_repo_shared_bare]$ git init --bare 
Initialized empty Git repository in /home/huang/git_repo_shared_bare/ 

(User 3) 
[/home/huang/git_repo_shared_bare]$ cd .. 
[/home/huang]$ mkdir User3 
[/home/huang]$ cd User3 
[/home/huang/User3]$ git clone /home/huang/git_repo_shared_bare 
Initialized empty Git repository in /home/huang/User3/git_repo_shared_bare/.git/ 
warning: You appear to have cloned an empty repository. 

(User 4) 
[/home/huang/User3]$ cd .. 
[/home/huang]$ mkdir User4 
[/home/huang]$ cd User4 
[/home/huang/User4]$ git clone /home/huang/git_repo_shared_bare 
Initialized empty Git repository in /home/huang/User4/git_repo_shared_bare/.git/ 
warning: You appear to have cloned an empty repository. 

(The revision made by User3 can syncronize to User4's folder) 
[/home/huang/User4]$ cd ~/User3/git_repo_shared_bare 
[/home/huang/User3/git_repo_shared_bare]$ echo test_user3 > test_user3.txt 
[/home/huang/User3/git_repo_shared_bare]$ git add test_user3.txt 


[/home/huang/User3/git_repo_shared_bare]$ git commit -m "test_user3.txt" 
[master (root-commit) 889a5c3] test_user3.txt 
Committer: huang <[email protected]> 
Your name and email address were configured automatically based 
on your username and hostname. Please check that they are accurate. 
You can suppress this message by setting them explicitly: 

    git config --global user.name "Your Name" 
    git config --global user.email [email protected] 

If the identity used for this commit is wrong, you can fix it with: 

    git commit --amend --author='Your Name <[email protected]>' 

1 files changed, 1 insertions(+), 0 deletions(-) 
create mode 100644 test_user3.txt 


[/home/huang/User3/git_repo_shared_bare]$ git push origin master 
Counting objects: 3, done. 
Writing objects: 100% (3/3), 242 bytes, done. 
Total 3 (delta 0), reused 0 (delta 0) 
Unpacking objects: 100% (3/3), done. 
To /home/huang/git_repo_shared_bare 
* [new branch]  master -> master 

[/home/huang/User3/git_repo_shared_bare]$ cd ~/User4/git_repo_shared_bare 
[/home/huang/User4/git_repo_shared_bare]$ git pull origin master 
remote: Counting objects: 3, done. 
remote: Total 3 (delta 0), reused 0 (delta 0) 
Unpacking objects: 100% (3/3), done. 
From /home/huang/git_repo_shared_bare 
* branch   master  -> FETCH_HEAD 
[/home/huang/User4/git_repo_shared_bare]$ ls 
test_user3.txt 

答えて

1

機会にそれほど必要ではありません。 共有の媒体(一般的なチームの "プッシュ/プル"リポジトリやGithubのホストされたリポジトリのような)として単に使われるリポジトリのチェックアウトされた作業ディレクトリがないので、それをスキップします。

これで大きな違いはないかもしれませんが、いくつかの共有ホストに多くのリポジトリがあると、それが積み重なります。保存されたHDDの容量だけではありませんが、作業ディレクトリは決して使用されていないため、完全に回避できます。

要するに、あなたはそれを熟考しています。 :)

+0

ありがとうございます。実験結果を追加しました。 「2016/08/09追加」を参照してください。 "--bare"が失敗することなくinitと思われました。そして、ここでのポイントは、Githubのすべてのリポジトリが裸のリポジトリであるということです。それが私が混乱した理由です。(私は通常のinitを試してからgithubにアップロードしました。この時点で、Githubでリポジトリを複製しようとした他のすべてのユーザは、 "ベアリポジトリ"をクローンしています) –

0
  1. 裸のレポは、私たちが裸のレポでgit checkoutを実行することはできませんを意味し、何の作業ツリーを持っていません。したがって、多くのディスクスペースを節約できます。

  2. デフォルトでは、安全でないためにチェックアウトされたリモート参照を更新するようにプッシュすることはできません。

関連する問題