How to replace a file in local repo with another one from remote repo?

血红的双手。 提交于 2019-12-13 04:48:37

问题


I did tried lots of approaches but I don't get what's really happening and how to fix it:

There are two git repos: remote and local (on my machine). Since I'm studying I experiment with code and do many changes in my local files. Usually then I do a revert for every file been changed then and I pull actual version of project from remote repo. But now I have one file (for example hello.jsp) that was changed by me and those changes were committed. And after that I have committed few times other changes related to other files. Well now I want to replace my local hello.jsp with same file from remote repo. So I did git pull --rebase and got merge conflict:

Applying: merge fixed
Using index info to reconstruct a base tree...
M       hello.jsp
<stdin>:10: trailing whitespace.
    function showHello() {
<stdin>:11: trailing whitespace.

<stdin>:12: trailing whitespace.
        document.getElementById('q').style.display = 'none';
<stdin>:13: trailing whitespace.
        document.getElementById('w').style.display = 'none';
<stdin>:14: trailing whitespace.
        document.getElementById('e').style.display = '';
warning: squelched 120 whitespace errors
warning: 125 lines add whitespace errors.
Falling back to patching base and 3-way merge...
Auto-merging hello.jsp
CONFLICT (content): Merge conflict in hello.jsp
Failed to merge in the changes.
Patch failed at 0001 merge fixed
The copy of the patch that failed is found in:
   d:/repo/helloProject/.git/rebase-apply/patch

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

well..First I tried to manually delete all changes I remember. But even if I use some kind of "show diff" it takes to much time to find all details were changed (believe me "hello.jsp" is very huge) Shame on me but I can't get what to do now.

I tried to do git reset "hello.jsp" and tried to do git checkout "hello.jsp" but it did not work. How just simply replace my "hello.jsp" with another one from remote repo?


回答1:


Try to checkout the file that you want. You have to specify the place from where you want it.

git checkout your_remote/your_branch filename


来源:https://stackoverflow.com/questions/18911802/how-to-replace-a-file-in-local-repo-with-another-one-from-remote-repo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!