简体   繁体   English

如何用远程仓库中的另一个替换本地仓库中的文件?

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

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). 有两个git repos:远程和本地(在我的机器上)。 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. 但是现在我有一个文件(例如hello.jsp )被我更改了,并且这些更改已提交。 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. 好吧,现在我想用远程hello.jsp中的相同文件替换本地hello.jsp So I did git pull --rebase and got merge conflict: 所以我做了git pull --rebase并发生合并冲突:

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. 但是,即使我使用某种“ show diff”,发现所有细节都需要花费很多时间(相信我“ hello.jsp”非常大),这让我感到羞耻,但我现在不知道该怎么办。

I tried to do git reset "hello.jsp" and tried to do git checkout "hello.jsp" but it did not work. 我试图做git reset "hello.jsp"并试图做git checkout "hello.jsp"但是没有用。 How just simply replace my "hello.jsp" with another one from remote repo? 如何仅用远程回购中的另一个替换我的“ hello.jsp”?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM