Cha*_*haz 18 git github git-fetch git-remote
这可能是非常基本的,但我还无法弄清楚:
我有一个 PHP 项目在两台服务器上运行,我们将其称为Live
两台Staging
服务器显然都在运行相同的项目,但有一些更改。
当这个项目到达我手中时,Github 上还没有,所以这就是我现在首先要做的事情。
我设法在 Github 上创建一个新的远程存储库并将Live
系统连接到它。
(通过将 Github 存储库添加为 'origin' Live
)
git remote add origin https://github.com/path-to-repo/repo.git
因此,Live System 目前位于master
分支上并且是最新的,origin/master
有 4 次提交的历史记录。
Staging
现在我也尝试连接 Github Repo
所以我做了一个
git init
git remote add origin https://github.com/path-to-repo/repo.git
git remote -v
origin https://github.com/path-to-repo/repo.git (fetch)
origin https://github.com/path-to-repo/repo.git (push)
git fetch
Run Code Online (Sandbox Code Playgroud)
现在,当我执行 git status 时,我看到存储库仍处于初始提交状态,并且所有文件和文件夹都列为未跟踪:
Run Code Online (Sandbox Code Playgroud)root@staging-host:/var/www/html# git status On branch master Initial commit Untracked files: (use "git add <file>..." to include in what will be committed) .htaccess README.md _index.html api/ app/ composer.json global/ index.php package-lock.json package.json phpinfo.php system/ vendor/ view/
与上次提交相比,我如何检查本地更改,origin/master
我不想丢失任何本地更改,但也不想提交或推送任何内容,
在我决定逐个文件提交哪些内容之前,我需要先检查差异重置什么
你的方法几乎是正确的。看看你的命令:
git remote add origin https://github.com/path-to-repo/repo.git
Run Code Online (Sandbox Code Playgroud)
这尝试将远程存储库添加为源并失败,因为它已经存在。
跑步
git remote -v
Run Code Online (Sandbox Code Playgroud)
您会看到这是您的实时存储库。以不同的方式命名,例如
git remote add staging https://github.com/path-to-repo/repo.git
Run Code Online (Sandbox Code Playgroud)
然后它应该可以工作。如果 origin 是 live 并且 staging 是 staging,那么拉、推到 staging 的方式如下:
git pull staging <branch>
Run Code Online (Sandbox Code Playgroud)
和
git push staging <branch>
Run Code Online (Sandbox Code Playgroud)
分别。如果我是你,我会更喜欢 origin 指向 staging,而另一个名为 live 的远程会指向 live,因为你会更频繁地使用 staging。
编辑
显然我误解了这个问题。基本上有一个由 GitHub 托管的存储库,您也想将其用于暂存。你不需要跑
git init
Run Code Online (Sandbox Code Playgroud)
在这种情况下也不添加遥控器。您只需要克隆存储库,例如
git clone https://github.com/path-to-repo/repo.git
Run Code Online (Sandbox Code Playgroud)