简体   繁体   English

无法访问旧git存储库时如何使用新的远程git存储库?

[英]How to use a new remote git repository when there is no access to old git repository?

I have a deployed web application. 我有一个已部署的Web应用程序。 The application has been deployed from a remote git repository. 该应用程序已从远程git存储库中部署。 Now, that repository was in someone else's control and we have no access to it. 现在,该存储库已由其他人控制,我们无法访问它。 I found there were some files edited on the server; 我发现服务器上编辑了一些文件。 so git status is showing some uncommitted changes. 因此git status显示了一些未提交的更改。 What I would like to do is - get all the code from server on my machine, do git init, commit all the code and push to a new remote repository, and then update the server to pull from this new repo. 我想做的是-从机器上的服务器中获取所有代码,执行git init,提交所有代码并推送到新的远程存储库,然后更新服务器以从此新存储库中提取信息。

Is this a right approach? 这是正确的方法吗? If yes, how do I handle the issues on the server related to uncommitted changes? 如果是,我该如何处理服务器上与未提交的更改相关的问题? How can I remove tracking on the server to the previous repo and point to the new repo without having to pull since the server has the latest code for now? 由于服务器目前具有最新代码,如何才能在服务器上删除对先前存储库的跟踪并指向新存储库而无需拉出?

If the history of the project (which you indicated is under someone else's control) is NOT important to you, it is a simply matter of copying all the code from the remote server and creating a NEW repository on your machine. 如果项目的历史记录(您指示的历史记录在别人的控制之下)对您而言并不重要,那么只需复制远程服务器上的所有代码并在计算机上创建一个新的存储库即可。

Remember, a git repository is a decentralized, atomic unit. 请记住,git存储库是一个分散的原子单元。 So the git repository presently on the server (I assume this is where you are getting the "uncommitted changes" message) can be ignored. 因此,可以忽略服务器上当前的git存储库(我假设这是您收到“未提交的更改”消息的位置)。 If you have SSH access on the server - which it sounds like - you could delete the .git/' directory and then use git init` to create a NEW repository that would be able to contain all the files on the server. 如果您在服务器上具有SSH访问权限(听起来像是),则可以删除.git/' directory and then use git init`创建一个新的存储库,该存储库将能够包含服务器上的所有文件。

From there, add a remote and PUSH as you need to. 从那里,根据需要添加一个遥控器和PUSH。

Since you seem to actually have access to a copy of that repository, I suggest the following: 由于您似乎实际上有权访问该存储库的副本,因此建议您执行以下操作:

Let's say the repository you have access to (the deployed app if I understand well) is accessible via ssh at user@production.com:/path/to/repo_folder and you want the new remote to be accessible at user@development.com:/path/to/repo.git . 假设您可以通过sshuser@production.com:/path/to/repo_folder访问您有权访问的存储库(如果我了解的话,已部署的应用程序),并且您希望可以在user@development.com:/path/to/repo.git上访问新的远程user@development.com:/path/to/repo.git

First, clone the repo in development.com : 首先,在development.com克隆仓库:

ssh user@development.com
cd /path/to
git clone --bare user@production.com:/path/to/repo_folder repo.git // This will create the folder "repo.git" which is a valid git repository without a working directory

Your new remote is set up, you can now update the tracking remotes on the deployed repository: 设置新的远程服务器后,您现在可以在已部署的存储库上更新跟踪远程服务器:

ssh user@production.com
cd /path/to/repo_folder
git remote add new_remote ssh://user@development.com/path/to/repo.git
// Do the following two commands for every branch you want to be tracked on the new remote:
git fetch new_remote/master
git branch --set-upstream-to new_remote/master

Finally, if you want to commit the modifications done in the repository you have access to, you have two solutions: 最后,如果要提交在有权访问的存储库中所做的修改,则有两种解决方案:

  1. Commit and push directly from that repository. 直接从该存储库提交并推送。 It's the most straightforward way but may be a bad idea if you don't have the unix users or configuration you want on that server. 这是最直接的方法,但是如果您在该服务器上没有想要的Unix用户或配置,则可能不是一个好主意。
  2. Clone the repository on your local machine (using the new remote), then reproduce the changes on your local repository. 在本地计算机上克隆存储库(使用新的远程服务器),然后在本地存储库上复制更改。 Commit and push. 提交并推送。 Log in on the server where the modifications was done first, discard them and pull from the new remote. 登录首先完成修改的服务器,丢弃它们并从新的远程服务器上拉取。

Note: I feel like my explanation is a bit vague, feel free to ask for precisions in the comment and I'll be happy to edit my answer! 注意:我觉得我的解释有点含糊,可以随时在评论中要求精确性,我很乐意编辑我的答案!

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

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