简体   繁体   English

尝试从存储库中提取信息时,为什么会出现合并错误?

[英]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.

相关问题 尝试将文件从本地驱动器添加到本地驱动器中的存储库时出现此错误 - I am getting this error when I am trying to add files from the local drive to the Repository in the local drive 为什么我会得到一个“目标路径”。 已经存在”尝试从我的网络服务器克隆时出现错误? - Why am I getting a “destination path '.' already exists” error when trying clone from my webfaction server? 试图从 github 拉我得到错误远程:找不到存储库 - Trying to pull from github i get error remote: Repository not found 为什么我的请求请求中得到额外的提交? - Why am I getting extra commits in my pull request? 当我从远程存储库中取出时,为什么Git会返回这些字符? - Why does Git returns these characters when I pull from my remote repository? 试图从我的 Github 存储库中提取文件:“拒绝合并不相关的历史” - Trying to pull files from my Github repository: “refusing to merge unrelated histories” 为什么我收到错误“致命:'C:/ Program Files(x86)/ Git'在存储库外”当我从存储库中运行“git reset --hard~1”时? - Why am I getting error “fatal: 'C:/Program Files (x86)/Git' is outside the repository” when I run “git reset --hard ~1” from within the repository? 为什么我会致命:文件来自Jenkins的存储库 - Why am I getting fatal: file is outside repository from Jenkins 我正在尝试将node js应用程序部署到heroku,但是在推送到master时仍然出现错误 - I am trying to deploy my node js app to heroku but I keep getting an error when pushing to master 为什么在尝试限制部署时会出现“权限被拒绝”的问题? - Why am I getting a “Permission Denied” when trying to cap deploy?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM