git pull:将本地版本替换为远程版本 [英] git pull: replace local version with the remote version

查看:172
本文介绍了git pull:将本地版本替换为远程版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

git pull命令有些我不理解的地方. 我有一个foobar Git存储库,其中包含两个文件,分别名为f1f2. 首先,我使用以下命令克隆此仓库:

There is something I don't understand with the git pull command. I have a foobar Git repository with two files, named f1 and f2. First, I clone this repo using this command:

git clone git@mycompany:foobar/foobar.git 

我对f1f2文件都进行了一些错误的修改,将它们添加到Git索引中,然后提交.

I make some wrong modifications to both the f1 and f2 files, add them to Git index and commit then.

git add -A
git commit -m 'a test wrong modification'

我现在确定此修改是错误的,我想用远程版本替换我的文件.所以我用git pull来做到这一点.

I decide now that this modifications were wrong and I want to replace my files with the remote version. So I use git pull to do this.

git pull

Already up-to-date.

Git回答该项目已经是最新的.我在做什么错了?我应该如何继续用远程版本替换本地版本?

Git answers that project is already up to date. What's wrong with what I'm doing? How should I proceed to replace my local version with the remote version?

推荐答案

git fetch origin
git reset --hard origin/master

以下是有关git pull git pull

Here is the good explanation about git pull git pull

git fetch命令将提交从远程存储库提交到本地存储库中.生成的提交存储为远程分支,而不是我们一直在使用的常规本地分支.这使您有机会在将更改集成到项目副本中之前查看更改.

The git fetch command imports commits from a remote repository into your local repo. The resulting commits are stored as remote branches instead of the normal local branches that we’ve been working with. This gives you a chance to review changes before integrating them into your copy of the project.

命令git pull <remote>获取当前分支的指定远程副本,并立即将其合并到本地副本中.这与git fetch <remote>后跟git merge origin/<current-branch>相同.由于它正在合并,因此您的提交仍然存在.

Command git pull <remote> fetches the specified remote’s copy of the current branch and immediately merge it into the local copy. This is the same as git fetch <remote> followed by git merge origin/<current-branch>. Since it is doing merge your commits were still there.

执行fetch后,您可以使用reset命令重置工作副本. Hard是忽略本地副本中的任何更改. git reset --hard origin/master

After doing fetch you can reset your working copy with reset command. Hard is to ignore any changes in your local copy. git reset --hard origin/master

这篇关于git pull:将本地版本替换为远程版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆