我正在尝试创建一个远程 git 存储库(我使用 --bare
选项对其进行了初始化)并将一些源文件推送到它。
我有一个本地 git 仓库和一个裸远程:
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/*
我创建了本地仓库:
1. 初始化
2. git 添加 *.ipynb
3. `git commit -m "首次导入 IPython Notebooks"
然后,我通过使用 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$
验证文件不在远程:
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 书中的远程章节,但我被难住了。
最佳答案
git push
除非您通过 Hook 脚本之一明确告诉它,否则不会更新远程端的工作目录。通常,如果你在远端 checkout 的分支是你正在推送的分支之一,它会大声提示并拒绝推送。但是,可以禁用该警告,允许您推送,但它仍然不会更新工作目录。您可以运行 git reset --hard HEAD
在您的远程存储库(或 git checkout master
或类似的东西)中,或设置一个 post-receive
Hook 为您做那件事或其他事情。不过,让远程存储库裸露可能更好 - 可能会引入第三个存储库,以便您的开发存储库可以推送到那里,而您的生产存储库可以从中提取。
编辑:好的,现在这是一个不同的问题,因为你提到你的远程存储库是用 --bare
创建的.如果您的远程存储库是裸的,那么您不应该期望以“正常”方式在那里看到您的文件,因为裸存储库没有与之关联的工作目录。相反,您会看到一些您通常会看到的子目录(如 branches
、hooks
、info
、objects
和 refs
)和文件(config
、description
、HEAD
)在 .git
下在非裸存储库中。您应该仍然能够运行 git log
和其他命令(如 git show HEAD:<some_file>
)来验证您的数据是否存在。
关于git - git push 到远程后目标目录为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13937816/