如何从远程提取文件而不覆盖本地文件? [英] How do I pull files from remote without overwriting local files?

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

问题描述



我希望我的本地文件覆盖远程仓库,但是git说:我希望我的本地文件覆盖远程仓库,我首先必须拉取这些远程文件并将它们合并。



有什么办法可以拉动但确保本地文件不被远程覆盖? / p>

解决方案

好吧,是的,没有...



您希望您的本地副本覆盖远程中的内容,但是,如果某人以某种不同方式修改了远程回购中的文件,而您只是忽略他们的变化,并试图强迫你自己的变化,甚至没有在可能的冲突中寻找,好吧,我为你(和你的同事)哭泣; - )

尽管如此,真的很容易做到正确的事情......

第1步:

  git存储


我们的本地回购。这会将您的本地更新保存到存储空间中,然后将修改后的文件恢复到预编辑状态。

第2步 / p>

  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天全站免登陆