[英]Why am I getting a merge error when trying to pull from my repository?
I have a git question about doing a git pull and it says 我有一个关于进行git pull的git问题,它说
error: Your local changes to the following files would be overwritten
by merge:
testFile.java
Please, commit your changes or stash them before you can merge. Aborting
If I just want overwrite this one file with the new file in the repository already how do I do it? 如果我只想用存储库中的新文件覆盖这个文件,该怎么办?
Can I fetch somehow and overwrite my local file? 我可以以某种方式获取并覆盖本地文件吗?
error: Your local changes to the following files would be overwritten by merge: schemas/rjtsml.xsd Please, commit your changes or stash them before you can merge. 错误:您对以下文件的本地更改将被合并覆盖:schemas / rjtsml.xsd请在合并之前提交更改或存储更改。 Aborting
堕胎
git checkout -- testFile.java
will overwrite local file with the one in the repo. git checkout -- testFile.java
将用git checkout -- testFile.java
的一个覆盖本地文件。 git checkout --help
if you need more info. git checkout --help
如果您需要更多信息。
As mardavi already mentioned on his answer, if you want to overwrite the local file with the version of the remote, you can do a simple git checkout -- testFile.java
. 正如mardavi在他的回答中已经提到的那样,如果您想用远程版本覆盖本地文件,则可以执行简单的
git checkout -- testFile.java
。 However , this will only update the file with the version from the remote that your .git
folder has information about. 但是 ,这只会使用
.git
文件夹具有有关其信息的远程版本来更新文件。 Since you've mentioned that you tried to do a git pull
, I'm assuming you want to update your local repository with a remote that might have been updated. 既然您已经提到过尝试进行
git pull
,那么我假设您想使用可能已更新的远程更新本地存储库。 If this is the case, you should do the following: 在这种情况下,您应该执行以下操作:
Overwrite the testFile.java file with the version that your .git
folder has information about: 使用您的
.git
文件夹具有以下信息的版本覆盖testFile.java文件:
git checkout -- testFile.java
Fetch data from the remote repository to update your database and merge it with your local branch. 从远程存储库中获取数据以更新数据库并将其与本地分支合并。 This is actually a description of the git-pull command.
这实际上是git-pull命令的描述。 So you simply execute:
因此,您只需执行:
git pull
And now your local branch should be up to date and the testFile.java has the newest changes from the remote server. 现在您的本地分支应该是最新的,并且testFile.java具有来自远程服务器的最新更改。
I recommend the following reading: Git Branching - Remote Branches 我建议阅读以下内容: Git分支-远程分支
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.