Git拉忽忽视局部变化? [英] Git Pull While Ignoring Local Changes?

查看:243
本文介绍了Git拉忽忽视局部变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以执行 git pull ,忽略任何本地文件更改,而不会将目录移开并且必须执行 git clone

Is there a way to do a git pull that ignores any local file changes without blowing the directory away and having to perform a git clone?

推荐答案

如果您的意思是您希望拉来覆盖本地更改,工作树很干净,干净的工作树:

If you mean you want the pull to overwrite local changes, doing the merge as if the working tree were clean, well, clean the working tree:

git reset --hard
git pull

如果有未跟踪的本地文件,您可以使用 git clean 删除它们。使用 git clean -f 删除未跟踪的文件, -df 删除未跟踪的文件和目录,使用 -xdf 删除未跟踪或忽略的文件或目录。

If there are untracked local files you could use git clean to remove them. Use git clean -f to remove untracked files, -df to remove untracked files and directories, and -xdf to remove untracked or ignored files or directories.

另一方面,如果您想以某种方式保留本地修改, 'd使用藏匿的方式将其藏起来,然后再重新使用它们:

If on the other hand you want to keep the local modifications somehow, you'd use stash to hide them away before pulling, then reapply them afterwards:

git stash
git pull
git stash pop

我认为从字面上理解 ignore 所做的更改 - 拉动的一半是合并,它需要将提交的内容版本与它提取的版本合并。

I don't think it makes any sense to literally ignore the changes, though - half of pull is merge, and it needs to merge the committed versions of content with the versions it fetched.

这篇关于Git拉忽忽视局部变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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