2017-09-28 19 views
0

我想使用git(在ubuntu服務器上)管理文件。我練習本地(mac),假設目錄ds是服務器,d1是user1,而d2是user2。git push但不添加或更改文件

這是我的工作流程:

$ mkdir ds 
$ cd ds 
$ git init 
$ echo '1' > 1.txt 
$ git add 1.txt 
$ git commit -m 'add 1.txt' 
[master (root-commit) 8eab711] add 1.txt 
1 file changed, 1 insertion(+) 
create mode 100644 1.txt 

,現在我想混帳克隆:

$ cd .. 
$ ls 
ds 
$ git clone ds d1 
$ git clone ds d2 
$ ls 
d1 d2 ds 

更改遠程存儲設置:

$ cd ds 
$ git config core.bare true 
$ git status 
fatal: This operation must be run in a work tree 

現在我試圖創建在D1文件。

$ cd ../d1 
$ ls 
1.txt 
$ echo '2' > 2.txt 
$ git add 2.txt 
$ git commit -m 'add 2.txt' 
[master 22242b8] add 2.txt 
1 file changed, 1 insertion(+) 
create mode 100644 2.txt 
$ ls 
1.txt 2.txt 
$ git log 
commit 22242b885bbc0d2189470dd720eaf0a0a0c97ce6 (HEAD -> master) 
Author: Name <[email protected]> 
Date: Thu Sep 28 10:44:48 2017 +0900 

    add 2.txt 

commit 8eab711880834e9e81e17d02cf6bd958e69fa58a (origin/master, origin/HEAD) 
Author: Name <[email protected]> 
Date: Thu Sep 28 10:38:48 2017 +0900 

    add 1.txt 

我試過檢查git remote -v,我確認沒有問題。 現在我試了push

$ git push 
Counting objects: 3, done. 
Delta compression using up to 4 threads. 
Compressing objects: 100% (2/2), done. 
Writing objects: 100% (3/3), 257 bytes | 257.00 KiB/s, done. 
Total 3 (delta 0), reused 0 (delta 0) 
To ..(skip)../Code/git/ds 
    8eab711..22242b8 master -> master 

$ls 
1.txt 2.txt 

現在我檢查ds目錄上的文件。這裏有一個問題。

$ cd ../ds 
$ ls 
1.txt 

只有'1.txt'。我檢查了git日誌。

$ git log 
commit 22242b885bbc0d2189470dd720eaf0a0a0c97ce6 (HEAD -> master) 
Author: Name <[email protected]> 
Date: Thu Sep 28 10:44:48 2017 +0900 

    add 2.txt 

commit 8eab711880834e9e81e17d02cf6bd958e69fa58a 
Author: Name <[email protected]> 
Date: Thu Sep 28 10:38:48 2017 +0900 

    add 1.txt 

我很困惑。在github中,我記得當我按下時,文件被更改了。 我嘗試了git pull在d2目錄中。

$ cd ../d2 
$ ls 
1.txt 
$ git pull 
remote: Counting objects: 3, done. 
remote: Compressing objects: 100% (2/2), done. 
remote: Total 3 (delta 0), reused 0 (delta 0) 
Unpacking objects: 100% (3/3), done. 
From ..(skip)../Code/git/ds 
    8eab711..22242b8 master  -> origin/master 
Updating 8eab711..22242b8 
Fast-forward 
2.txt | 1 + 
1 file changed, 1 insertion(+) 
create mode 100644 2.txt 
$ ls 
1.txt 2.txt 

哦,我的天啊,2.txt出現了。

該文件在ds中沒有改變?我如何讓所有存儲庫中的文件保持一致?

謝謝。

+0

如果可以避免,請勿手動設置core.bare。用--bare克隆。你不需要做那麼多手動工作 –

回答

1

你必須在DS

git pull 

。除非您使用命令(git fetch),否則您的本地副本將不知道遙控器上是否有新增內容。

+0

謝謝你的回答。我嘗試過,但我得到了'致命的:這個操作必須在工作樹中運行'。 – Centell

+0

哦,我有'致命的:沒有指定遠程存儲庫。請指定一個URL或一個 遠程名稱,從中應該提取新的修訂版本.'當命令'git fetch' – Centell