简体   繁体   English

git复制本地文件夹覆盖在线仓库

[英]git copied local folder overwrite online repo

So I've copied a local git folder, and made a lot of changes in it. 因此,我已经复制了本地git文件夹,并对其进行了许多更改。 I would like to overwrite the online repo with this new one (so basically remove the link with the previous one, and copy this new one to the online repo and go from there on). 我想用这个新的仓库覆盖在线仓库(因此,基本上删除与前一个仓库的链接,然后将这个新仓库复制到在线仓库并从那里继续)。

So far I tried: 到目前为止,我尝试了:

git push -f origin master

and this did what I wanted (it seems). 这确实满足了我的要求(看来)。 But now if I want to push, I first get the message: 但是现在,如果我要推送,我首先会收到以下消息:

 git push --set-upstream origin master

Then after doing that: error: failed to push some refs to 'git@bitbucket.org:**************' hint: Updates were rejected because the remote contains work that you do hint: not have locally. 然后执行以下操作:错误:无法将一些引用推送到'git@bitbucket.org:**************'提示:更新被拒绝,因为远程包含您确实提示的工作:在本地没有。 This is usually caused by another repository pushing hint: to the same ref. 这通常是由另一个存储库推送提示引起的:指向相同的引用。 You may want to first integrate the remote changes hint: (eg, 'git pull ...') before pushing again. 您可能需要先整合远程更改提示:(例如,'git pull ...'),然后再再次推送。 hint: See the 'Note about fast-forwards' in 'git push --help' for details. 提示:有关详细信息,请参见“ git push --help”中的“关于快进的注意事项”。

I understand it's because my other folder is interfering? 我了解这是因为我的其他文件夹干扰了吗? But I'm afraid to pull the repo in, because it will overwrite my local folder? 但是我担心要拉回购协议,因为它会覆盖我的本地文件夹吗?

So I tryd to remove the git in the original folder, but that's not helping. 所以我试图删除原始文件夹中的git,但这无济于事。

So now my question: How can I overwrite the online repo with this new local repo and start from there on? 所以现在我的问题是:如何用这个新的本地仓库覆盖在线仓库并从那里开始呢?

Thank you for your help! 谢谢您的帮助!

The OP has answered the question, but that is not the correct way to do things in git. OP已经回答了这个问题,但这不是在git中做事的正确方法。 Hence, suggesting a generally followed approach 因此,建议采取一般遵循的方法


You can follow the below procedure 您可以按照以下步骤

1) do git pull . 1)做git pull

2) It may ask you to commit or stash the changes if there would be conflicts. 2)如果有冲突,它可能会要求您提交或存储更改。 If it doesn't then skip step 3 如果没有,请跳过步骤3

3) if it does, then do git stash followed by git pull . 3)如果这样做,则先执行git stash ,再执行git pull

4) If you had stashed(step 3) then you need to do git stash pop after git pull or else skip this step 4)如果您已藏匿(步骤3),则需要在git pull之后执行git stash pop ,否则请跳过此步骤

5) After the above procedure, you may or may not get conflicts. 5)完成上述步骤后,您可能会或可能不会发生冲突。 If you do not get conflicts, then you are lucky enough. 如果没有冲突,那么您很幸运。 IF you do, then resolve the conflicts and then commit it 如果您这样做,则解决冲突然后再提交

6) Now you can do git push 6)现在您可以执行git push

So, I ended up making a back-up. 因此,我最终做了一个备份。 Then I ran 然后我跑了

git pull

After doing 做完之后

git push --set-upstream master origin

I am able to do push and commit without any problems! 我能够毫无问题地进行推送和提交!

You can add branch for just for your new code. 您可以为新代码添加分支。 So the code from master branch wont overwrite your code. 因此,来自master分支的代码不会覆盖您的代码。

After you submit your branch you can see diff between branches. 提交分支后,您可以看到分支之间的差异。

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

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