Git的推推什么Git

2023-09-11 09:29:00 作者:泪湿了眼眶

我有2个远程的回购协议:一个在到位桶,另一个在Amazon EC2上。我最近又增加了第二个。

I have 2 remote repos: one at bitbucket, another at amazon ec2. I added the second one recently.

git remote -v

ec2 ubuntu@xx.xx.xx.xx:/home/ubuntu/my_app.git (fetch)
ec2 ubuntu@5xx.xx.xx.xx:/home/ubuntu/my_app.git (push)
origin  ssh://git@bitbucket.org/me/my_app.git (fetch)
origin  ssh://git@bitbucket.org/me/my_app.git (push)

当我把产地它工作得很好。但是,当我推到EC2上,它也似乎运作良好,但通过 SSH 看不出有什么再推。我已经做了2次了,但是我没有源在那里。 这是一个Git目录的EC2:

When I push origin it works well. But when I push to ec2, it also seems to work well, however via ssh don't see anything it pushed. I've done it 2 times already but I there is no source in there. Here is a git directory at ec2:

ubuntu@ip-xx-xx-xx-xx:~/my_app.git$ ls -al
total 40
drwxrwxr-x  7 ubuntu ubuntu 4096 Mar 15 01:52 .
drwxr-xr-x  6 ubuntu ubuntu 4096 Mar 15 01:50 ..
drwxrwxr-x  2 ubuntu ubuntu 4096 Mar 15 01:52 branches
-rw-rw-r--  1 ubuntu ubuntu   66 Mar 15 01:52 config
-rw-rw-r--  1 ubuntu ubuntu   73 Mar 15 01:52 description
-rw-rw-r--  1 ubuntu ubuntu   23 Mar 15 01:52 HEAD
drwxrwxr-x  2 ubuntu ubuntu 4096 Mar 15 12:04 hooks
drwxrwxr-x  2 ubuntu ubuntu 4096 Mar 15 13:30 info
drwxrwxr-x 10 ubuntu ubuntu 4096 Mar 15 13:30 objects
drwxrwxr-x  4 ubuntu ubuntu 4096 Mar 15 01:52 refs

我把这个建议Can't推到EC2资源库 - 无法解析主机名添加EC2作为一个远程的git回购

I took this advice Can't push to ec2 repository - Could not resolve hostname for adding ec2 as a remote git repo.

下面是推之一:

$ git push ec2 master
Counting objects: 9, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 749 bytes | 0 bytes/s, done.
Total 6 (delta 3), reused 0 (delta 0)
To ubuntu@xx.xx.xx.xx:/home/ubuntu/my_app.git
   123..123abc  master -> master

请注意:只有一个分支,gitk正确显示的一切。它只是不推什么EC2。

Note: there is only one branch, gitk displays everything correctly. It just doesn't push anything to ec2.

推荐答案

您已经在EC2实例创建的回购协议是一个裸露的回购协议。所以,正因为如此,你将不会看到任何code文件在那里,只有 git的斑点您的回购。检查这和的这个。

The repo you have created on your EC2 instance is a bare repo. So, as such, you won't see any code files over there, only the git blobs of your repo. Check this and this.

的方法来检查,如果code其实是被推为

The way to check if the code is actually being pushed will be

ssh ubuntu@xx.xx.xx.xx #log-in to your EC2 server
git clone my_project my_project.git

现在该文件夹中的 MY_PROJECT ,你会发现实际的code检查。

Now in the folder my_project, you will find the actual code checked out.

所以,在这种情况下,你的正常工作流程是这样的

So, your normal work flow in this case will be something like

git push ec2 master #from your dev machine
ssh ubuntu@xx.xx.xx.xx #log-in to your EC2 server
cd my_project
git pull origin master #after last clone, the original bare repo became the origin repo for this clone

以上后,任何新的code你推将可在这里。

After the above, any new code you push will be available here as well.

修改的

EDIT

在你的情况,你已经到位桶使用,所以我建议探索这个工作流程 - 从克隆到位桶回购,并使用作为到位桶的基准点,无论是在EC2上,并从本地开发环境。这将释放你的服务器上的任何备份相关的麻烦你。您可以添加到位桶多个SSH密钥,所以你需要生成你的EC2的钥匙,并添加公钥到位桶。

In your case, you are already using bitbucket, so I would suggest exploring this workflow - clone the repo from bitbucket, and use the bitbucket as the reference point, both on ec2, and from your local dev environment. This will free you of any backup related hassles on your server. You can add multiple ssh keys on bitbucket, so you will need to generate the keys on your ec2 and add the public key to bitbucket.

因此​​,在这种情况下,

So in this case,

在推$ C $从开发的C到位桶到 SSH来EC2 在EC2上,无论是使用克隆到位桶回购 git的克隆https_bitbucket_url 在EC2上或设置SSH密钥和现在使用 git的克隆ssh_bitbucket_url 或新的非裸露的回购协议,添加一个新的远程到位桶使用的URL。 push code from your Dev to bitbucket Ssh to ec2 On ec2, either clone the bitbucket repo using git clone https_bitbucket_url Or setup ssh keys on ec2 and now use git clone ssh_bitbucket_url Or to a new non bare repo, add a new remote using bitbucket URL.