话虽如此,但做正确的事..."真的很容易第 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 stashin 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 pullto 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 popThat 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. 这篇关于如何在不覆盖本地文件的情况下从远程拉取文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-15 14:09