如何在不覆盖本地文件的情况下从远程拉取文件? [英] How do I pull files from remote without overwriting local files?

查看:33
本文介绍了如何在不覆盖本地文件的情况下从远程拉取文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将新的 git 存储库设置为预先存在的远程存储库.

我希望我的本地文件覆盖远程存储库,但是 git 说我首先必须将这些远程文件拉入并合并它们.

有没有办法拉取但确保本地文件不被远程覆盖?

解决方案

嗯,是的,也不是...

我知道您希望您的本地副本覆盖"远程中的内容,但是,哦,伙计,如果有人以某种不同方式修改了远程存储库中的文件,而您只是忽略他们的更改并尝试强制"您自己的更改,甚至查看可能的冲突,好吧,我为您(和您的同事)哭泣;-)

话虽如此,但做正确的事..."真的很容易

第 1 步:

git stash

在您的本地存储库中.这会将您的本地更新保存到存储中,然后将修改后的文件恢复到编辑前的状态.

第 2 步:

git pull

获取任何修改版本.现在,希望不会得到您担心的文件的任何新版本.如果没有,那么下一步将顺利进行.如果它确实,那么你有一些工作要做,你会很高兴你做到了.

第 3 步:

git stash pop

这会将您在第 1 步中隐藏的修改版本与您在第 2 步中刚刚提取的版本合并.如果一切顺利,那么您就大功告成了!

另一方面,如果您在第 2 步中提取的内容与您的修改(由于其他人在此期间进行编辑)之间存在真正冲突,您会发现并被告知来解决它们.做吧.

事情会以这种方式好转 - 它可能会保留您的更改,而无需您进行任何实际工作,同时提醒您注意严重的问题.

I am trying to set up a new git repo to a pre-existing remote repo.

I want my local files to overwrite the remote repo, but git says that I first have to pull those remote files in and merge them.

Is there any way to pull but make sure that the local files are not overwritten by the remote?

解决方案

Well, yes, and no...

I understand that you want your local copies to "override" what's in the remote, but, oh, man, if someone has modified the files in the remote repo in some different way, and you just ignore their changes and try to "force" your own changes without even looking at possible conflicts, well, I weep for you (and your coworkers) ;-)

That said, though, it's really easy to do the "right thing..."

Step 1:

git stash

in your local repo. That will save away your local updates into the stash, then revert your modified files back to their pre-edit state.

Step 2:

git pull

to get any modified versions. Now, hopefully, that won't get any new versions of the files you're worried about. If it doesn't, then the next step will work smoothly. If it does, then you've got some work to do, and you'll be glad you did.

Step 3:

git stash pop

That will merge your modified versions that you stashed away in Step 1 with the versions you just pulled in Step 2. If everything goes smoothly, then you'll be all set!

If, on the other hand, there were real conflicts between what you pulled in Step 2 and your modifications (due to someone else editing in the interim), you'll find out and be told to resolve them. Do it.

Things will work out much better this way - it will probably keep your changes without any real work on your part, while alerting you to serious, serious issues.

这篇关于如何在不覆盖本地文件的情况下从远程拉取文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆