gpt4 book ai didi

git - 是否可以将多个本地文件夹连接到 Github 中的一个存储库?

转载 作者:行者123 更新时间:2023-12-04 11:38:46 26 4
gpt4 key购买 nike


我有两个不同路径的不同文件夹,我想将它们链接到同一个存储库。出于说明目的,两个不同的文件夹是

Folder 1: C:\Users\Tea\Folder1
Folder 2: C:\Users\Tea\Folder2
文件夹 1 最初链接到我的存储库,但我也想将文件夹 2 链接到存储库,以便我也可以从那里推送文件。
这是我尝试过的
cd C:\Users\Tea\Folder2
git init
git add .
git commit -m "initial commit from Folder 2"
git remote set-url origin --push --add http://github.com/<my username and repository>
最后一行是根据这篇文章完成的: pull/push from multiple remote locations
但是,我在执行时收到错误消息
git push origin master
要我做一个 git fetch。更具体地说,它写道:
! [ rejected ] master -> master(fetch first)
error: failed to push some refs to 'https://github.com/...'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull...') before pushing again
所以我做了 git pull origin master而是收到了这些消息
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
我尝试 merge 但得到了
fatal: refusing to merge unrelated histories
所以我决定做
git push -f origin <branch>
根据 Cannot push to GitHub - keeps saying need merge
不知道“丢失所有提交”是什么意思(我认为这只是意味着当前的提交消息将丢失)。
事实证明,这对我来说是一个错误的决定,因为我链接到 git 存储库的新文件夹完全替换了我的旧 git 存储库(即所有旧文件现在都不见了)。
tl; dr:如何将两个单独的文件夹链接到一个 Github 存储库?
提前致谢!

最佳答案

I have two different folders with different paths and I want to link them to the same repository. For illustration purposes ...So is there a way I can link two separate folders to one Github repository, preferably without having to merge them?



Tl;博士

不,GIT 不会像这样工作 .您可以将一个链接到一个远程,您不能将多个本地存储库链接到一个远程。

git init
git add NewFolder
git commit -m "web automation basics"
git remote set-url origin --push --add http://github.com/<my username and repository>

  • git init创建一个新的仓库
  • 然后你添加一些东西
  • 并将其链接到远程

  • git push origin master However, I got an error message...asking me to do a git pull



    然后你试着把它推送到你的 Remote ,但这个 Remote 已经链接到另一个仓库,所以 GIT 认为你的本地有冲突,因为它们不一样。

    So I did git pull origin master and got these messages instead

    hint: Updates were rejected because the tip of your current branch is behind
    hint: its remote counterpart. Integrate the remote changes (e.g.
    hint: 'git pull ...') before pushing again.
    hint: See the 'Note about fast-forwards' in 'git push --help' for details.


    所以你现在尝试了 pull 并且 GIT 拒绝了它,因为我们完全不同的两个 repos。您尝试 merge ,但这(显然)失败了,因为它们没有任何共同点。

    so I decided to do

    git push -f origin <branch>


    在这一点上,您基本上用本地副本覆盖了您的 Remote ( -f 是强制标志,您将更改强制到存储库,忽略冲突等)。所以会有一个提交,删除仓库中的所有内容并添加第二个仓库中的所有内容。

    关于git - 是否可以将多个本地文件夹连接到 Github 中的一个存储库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51359454/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com