繁体   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