git push to remote后目标目录为空

Dan*_*Dye 5 git

我正在尝试创建一个远程git仓库(我用该--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/*
Run Code Online (Sandbox Code Playgroud)

我创建了本地仓库:1.2 git init . git add *.ipynb 3.`git commit -m"首次导入IPython笔记本"

然后,我通过使用vi编辑*.ipynb文件然后运行来验证我的本地存储库已跟踪其中的文件git status.git确实看到了更改的文件.

但是,当我执行git push nbcsm master推送似乎成功但我的远程计算机/实例上的目标目录是空的(即它不包含我试图推送到远程的文件):

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$
Run Code Online (Sandbox Code Playgroud)

验证文件不在远程:

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:~$ 
Run Code Online (Sandbox Code Playgroud)

本地仓库中大约有12个.ipynb文件未被推送.我很确定这是一个概念问题,而不是语法问题,但我已阅读并重新阅读O'Reilly Git书中的Remote章节,我很难过.

twa*_*erg 5

git push除非您通过钩子脚本之一明确告诉它,否则不会更新远程端的工作目录。通常,如果您在远端签出的分支是您要推送的分支之一,它将大声抱怨并拒绝推送。但是,可以禁用该警告,允许您进行推送,但是它仍然不会更新工作目录。您既可以git reset --hard HEAD在远程存储库(或git checkout master类似的存储库)中运行,也可以设置一个post-receive挂钩来为您执行此操作。不过,最好使裸露的存储库裸露-可能引入第三个存储库,以便您的开发存储库可以推送到那里,而生产存储库可以从中取出。

编辑:好的,现在这是一个不同的问题,因为您提到您的远程存储库是使用创建的--bare。如果远程存储库是裸露的,那么您不应期望以“正常”方式在此处看到文件,因为裸露的存储库没有与之关联的工作目录。相反,你会看到几个子目录(如brancheshooksinfoobjectsrefs)和文件(configdescriptionHEAD),你通常会看到下.git在非纯仓库。不过,您仍然应该能够运行git log和其他命令(例如git show HEAD:<some_file>)来验证数据是否存在。