簡體   English   中英

git push to remote后目標目錄為空

[英]target directory empty after git push to remote

我正在嘗試創建一個遠程git --bare (我用--bare選項初始化)並將一些源文件推送到它。

我有一個本地的git repo和一個裸的遙控器:

ubuntu@ip-LOCAL-IP:~/notebooks$ cat .git/config  
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[branch "master"]
[remote "nbcsm"]
    url = ssh://ubuntu@ec2-RE-DA-CT-ED.compute1.amazonaws.com/home/ubuntu/notebooks/.git
    fetch = +refs/heads/*:refs/remotes/nbcsm/*

我創建了本地git add *.ipynb git init 2. git add *.ipynb commit -m“首次導入IPython筆記本”

然后,我通過使用vi編輯* .ipynb文件然后運行git status來驗證我的本地存儲庫已跟蹤其中的文件。 git確實看到了更改的文件。

但是,當我執行git push nbcsm master ,push似乎成功,但我的遠程計算機/實例上的目標目錄是空的(即它不包含我試圖推送到遠程的文件):

ubuntu@ip-LOCAL-IP:~/notebooks$ git push nbcsm master
Enter passphrase for key '/home/ubuntu/.ssh/id_rsa': 
Counting objects: 11, done.
Compressing objects: 100% (9/9), done.
Writing objects: 100% (9/9), 2.49 KiB, done.
Total 9 (delta 5), reused 0 (delta 0)
To ssh://ubuntu@ec2-ec2-RE-DA-CT-ED.amazonaws.com/home/ubuntu/notebooks/.git
7a50f44..295a4fa  master -> master
ubuntu@ip-LOCAL-IP:~/notebooks$

驗證文件不在遠程:

ubuntu@ip-LOCAL-IP:~/notebooks$ ssh ubuntu@ec2-ec2-RE-DA-CT-ED.compute-1.amazonaws.com
Enter passphrase for key '/home/ubuntu/.ssh/id_rsa': 
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-25-virtual x86_64)

* Documentation:  https://help.ubuntu.com/

System information as of Tue Dec 18 16:46:23 UTC 2012

System load:  0.02              Processes:           63
Usage of /:   41.7% of 7.97GB   Users logged in:     0
Memory usage: 12%               IP address for eth0:REMOTE-IP
Swap usage:   0%

Graph this data and manage this system at https://landscape.canonical.com/

Get cloud support with Ubuntu Advantage Cloud Guest
http://www.ubuntu.com/business/services/cloud
*** /dev/xvda1 will be checked for errors at next reboot ***

ubuntu@REMOTE-IP:~$ sudo find /home/ubuntu/ -name "*.ipynb"  
/home/ubuntu/notebooks/Untitled0.ipynb
ubuntu@ip-REMOTE-IP:~$ 

本地倉庫中大約有12個.ipynb文件未被推送。 我很確定這是一個概念問題,而不是語法問題,但我已閱讀並重新閱讀O'Reilly Git書中的Remote章節,我很難過。

除非您通過其中一個鈎子腳本明確告訴它,否則git push不會更新遠程端的工作目錄。 通常,如果您在遠程端檢出的分支是您正在推動的分支之一,它將大聲抱怨並拒絕推送。 但是,可以禁用該警告,允許您進行推送,但仍然不會更新工作目錄。 您可以在遠程存儲庫(或git checkout master或類似的東西)中運行git reset --hard HEAD ,或者為您或其他東西設置post-receive hook。 但是,讓遠程存儲庫裸露可能更好 - 可能會引入第三個存儲庫,以便您的開發回購可以推送到那里,並且您的生產回購可以從中獲取。

編輯:好的,現在這是一個不同的問題,因為你提到你的遠程存儲庫是用--bare創建的。 如果您的遠程存儲庫是裸的,那么您不應該期望以“正常”方式看到您的文件,因為裸存儲庫沒有與之關聯的工作目錄。 相反,您將看到一些子目錄(如brancheshooksinfoobjectsrefs )和文件( configdescriptionHEAD ),您通常.git在非裸存儲庫中看到.git 您應該仍然能夠運行git log和其他命令(例如git show HEAD:<some_file> )來驗證您的數據是否存在。

git status看到文件發生了變化的git status

git status應該告訴你沒有文件被修改!

git status
# On branch master
nothing to commit (working directory clean)

如果它列出了修改過的文件,則需要在推送之前添加並提交這些文件:

git add .
git commit -m "my commit message"
git push -u  nbcsm master 

另外,請確保並檢查服務器端檢出的分支:

cd /home/ubuntu/notebooks
git branch

如果沒有警告,您應該無法推送到非裸倉。
但由於您沒有,可能會檢出另一個分支。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM