我正在使用Git 1.7.4.1.我想从存储库中获取最新版本的代码,但我收到错误...
$ git pull
….
M selenium/ant/build.properties
….
M selenium/scripts/linux/get_latest_updates.sh
M selenium/scripts/windows/start-selenium.bat
Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>' as appropriate to mark resolution, or use 'git commit -a'.
Run Code Online (Sandbox Code Playgroud)
我删除了该工具抱怨的文件的本地副本,但我仍然得到错误.如何查看远程仓库的最新版本? - 戴夫
Ale*_*tis 245
如果您不关心任何本地更改(包括刚刚发生在这里的未跟踪或生成的文件或子存储库),只需要来自repo的副本:
git reset --hard HEAD
git clean -xffd
git pull
Run Code Online (Sandbox Code Playgroud)
同样,这将会破坏您在本地所做的任何更改,因此请谨慎使用.想一想rm -Rf这样做.
tvl*_*tvl 215
案例1:不关心当地的变化
解决方案1:获取最新代码并重置代码
git fetch origin
git reset --hard origin/[tag/branch/commit-id usually: master]
Run Code Online (Sandbox Code Playgroud)解决方案2:删除文件夹并再次克隆:D
rm -rf [project_folder]
git clone [remote_repo]
Run Code Online (Sandbox Code Playgroud)案例2:关注当地的变化
解决方案1:与新版在线版没有冲突
git fetch origin
git status
Run Code Online (Sandbox Code Playgroud)
会举报如下:
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
Run Code Online (Sandbox Code Playgroud)
然后获取最新版本
git pull
Run Code Online (Sandbox Code Playgroud)解决方案2:与新在线版本冲突
git fetch origin
git status
Run Code Online (Sandbox Code Playgroud)
会举报如下:
error: Your local changes to the following files would be overwritten by merge:
file_name
Please, commit your changes or stash them before you can merge.
Aborting
Run Code Online (Sandbox Code Playgroud)
提交您的本地更改
git add .
git commit -m ‘Commit msg’
Run Code Online (Sandbox Code Playgroud)
尝试获取更改(将失败)
git pull
Run Code Online (Sandbox Code Playgroud)
会举报如下:
Pull is not possible because you have unmerged files.
Please, fix them up in the work tree, and then use 'git add/rm <file>'
as appropriate to mark resolution, or use 'git commit -a'.
Run Code Online (Sandbox Code Playgroud)
打开冲突文件并修复冲突.然后:
git add .
git commit -m ‘Fix conflicts’
git pull
Run Code Online (Sandbox Code Playgroud)
会举报如下:
Already up-to-date.
Run Code Online (Sandbox Code Playgroud)更多信息: 如何使用'git reset --hard HEAD'恢复到之前的提交?
Kzq*_*qai 17
我怀疑发生了什么可能是你删除了你修改过的文件(因为你不关心那些更改),现在git将删除作为一个更改.
这是一种方法,可以将您的更改从您的工作副本中移出并进入"存储"(如果它实际上已经再次需要它们,则可以检索),这样您就可以从上游获取最新的更改.
git stash
git pull
Run Code Online (Sandbox Code Playgroud)
如果您想要检索文件(与上游更改和所有文件的潜在冲突),请运行a git stash apply以在代码之上粘贴这些更改.这样,你就有了"撤消"的方法.
试试这个代码
cd /go/to/path
git pull origin master
Run Code Online (Sandbox Code Playgroud)
您必须先合并文件.做一个git status以查看需要合并的文件是什么(意味着您需要先解决冲突).一旦这样做,做git add file_merged,做你的pull一次.