做一个Git拉来覆盖本地更改 [英] Do a Git pull to overwrite local changes
问题描述
肯定有这样的帖子,但我实际上做了一次提交,因为我认为这是正确的做法。
所以,我有两个存储库,一个开发和一个生产。我不得不在生产环境中编辑一些东西,因为它是一个紧急的bug修复,现在我有三个文件比生成中的更新。我犯了生产中的三个文件并尝试了一次拉,但它告诉我存在合并错误。我试图将新文件复制并粘贴到开发服务器,然后重试整个过程,但它不起作用。现在我确定我需要的是开发(因为我复制并粘贴到它)并承诺,所以我怎么能拉和覆盖冲突的文件?
----跟随@Seths回复
好的,我想我需要重新说明我的问题: )
我有三个存储库。一个是GitHub和一个产品的开发。
通常更新生产我只是从开发推动到GitHub, git pull origin master
(从GitHub到生产),并且它可以工作。
不幸的是,我在没有存储的情况下更改了生产文件。如何强制覆盖而不是合并时尝试拉?
如果您想完全替换您的本地分支foo与
git fetch origin
git checkout foo
git reset - 如果你想做其他事情,请将你的问题重新填上你的问题。但是,我可能会将生产Git仓库添加为远程,然后合并实时更改,而不是您尝试的任何操作。
There has certainly been posts around for this, but I actually did a commit because I thought it was the right thing to do.
So, I have two repositories, one development and one production. I had to edit something in the production because it was an urgent bugfix, and now I have three files that are newer in the production than in the development.
I committed the three files on the production and tried a pull, but it told me there were merge errors. I tried copying and pasting the new files to the development server and retrying the whole thing and it didn't work. Now I'm sure that what I need is on the development (since I copied and pasted into it) and committed, so how could I pull and overwrite the conflicting files?
---- Following up to @Seths reply
Ok, I guess I do need to reword my question :)
I have three repositories. One development, one in GitHub and one production.
Usually to update production I just do a push from development to GitHub, git pull origin master
(from GitHub to production), and it works.
Unfortunately, I changed files on production without stashing. How do I force overwrite instead of merge when trying a pull?
解决方案 If you want to entirely replace your local branch foo with the contents of the remote branch origin/foo:
git fetch origin
git checkout foo
git reset --hard origin/foo
If you want to do something else, please reword your question. However, I might add the production Git repository as a remote and then merge the live changes in, instead of whatever you tried.
这篇关于做一个Git拉来覆盖本地更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!