简体   繁体   English

git push to remote后目标目录为空

[英]target directory empty after git push to remote

I'm attempting to create a remote git repo, (which I initialized with the --bare option) and push some source files to it. 我正在尝试创建一个远程git --bare (我用--bare选项初始化)并将一些源文件推送到它。

I have a local git repo and a bare remote: 我有一个本地的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/*

I created the local repo with: 1. git init 2. git add *.ipynb 3. `git commit -m "first import of IPython Notebooks" 我创建了本地git add *.ipynb git init 2. git add *.ipynb commit -m“首次导入IPython笔记本”

I then verified that my local repo has tracked files in it by using vi to edit an *.ipynb file and then running git status . 然后,我通过使用vi编辑* .ipynb文件然后运行git status来验证我的本地存储库已跟踪其中的文件。 git does see the changed file. git确实看到了更改的文件。

However, when I execute git push nbcsm master the push appears to be successful but the target directory on my remote computer/instance is empty (ie it doesn't contain the files I'm trying to push to the remote): 但是,当我执行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$

Verifying that the files aren't on remote: 验证文件不在远程:

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:~$ 

There are about 12 *.ipynb files in the local repo that are not being pushed. 本地仓库中大约有12个.ipynb文件未被推送。 I'm fairly certain that this is a conceptual issue rather than a syntax issue but I've read and re-read the Remote chapter in the O'Reilly Git book and I'm stumped. 我很确定这是一个概念问题,而不是语法问题,但我已阅读并重新阅读O'Reilly Git书中的Remote章节,我很难过。

git push will not, unless you explicitly tell it to via one of the hook scripts, update the working directory on the remote end. 除非您通过其中一个钩子脚本明确告诉它,否则git push不会更新远程端的工作目录。 Usually, if the branch you have checked out on the remote end is one of the branches you are pushing, it will complain loudly and refuse the push. 通常,如果您在远程端检出的分支是您正在推动的分支之一,它将大声抱怨并拒绝推送。 However, that warning can be disabled, allowing you to push, but it still won't update the working directory. 但是,可以禁用该警告,允许您进行推送,但仍然不会更新工作目录。 You can either run git reset --hard HEAD in your remote repository (or git checkout master or something similar), or set up a post-receive hook to do that for you or something. 您可以在远程存储库(或git checkout master或类似的东西)中运行git reset --hard HEAD ,或者为您或其他东西设置post-receive hook。 It's probably better to have the remote repository be bare, though - possibly introducing a third repository so that your development repo can push there, and your production repo can pull from it. 但是,让远程存储库裸露可能更好 - 可能会引入第三个存储库,以便您的开发回购可以推送到那里,并且您的生产回购可以从中获取。

Edit: Ok, now this is a different question, since you mention your remote repository was created with --bare . 编辑:好的,现在这是一个不同的问题,因为你提到你的远程存储库是用--bare创建的。 If your remote repository is bare, then you should not expect to see your files there in a "normal" way, because a bare repository does not have a working directory associated with it. 如果您的远程存储库是裸的,那么您不应该期望以“正常”方式看到您的文件,因为裸存储库没有与之关联的工作目录。 Instead you'll see a few subdirectories (like branches , hooks , info , objects and refs ) and files ( config , description , HEAD ) that you would normally see under .git in a non-bare repository. 相反,您将看到一些子目录(如brancheshooksinfoobjectsrefs )和文件( configdescriptionHEAD ),您通常.git在非裸存储库中看到.git You should still be able to run git log and other commands (like git show HEAD:<some_file> ) to verify that your data is there, though. 您应该仍然能够运行git log和其他命令(例如git show HEAD:<some_file> )来验证您的数据是否存在。

git status that git sees the file changed. git status看到文件发生了变化的git status

git status should tell you that no file is being modified! git status应该告诉你没有文件被修改!

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

If it lists modified files, you need to add and commit those files first , before pushing: 如果它列出了修改过的文件,则需要在推送之前添加并提交这些文件:

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

Plus, make sure and check what branch is checked out on the server side: 另外,请确保并检查服务器端检出的分支:

cd /home/ubuntu/notebooks
git branch

You shouldn't be able to push to a non-bare repo without a warning. 如果没有警告,您应该无法推送到非裸仓。
But since you didn't have one, it is possible that another branch is checked out. 但由于您没有,可能会检出另一个分支。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM