有没有一种方法来做一个git拉,忽略任何本地文件的变化,而不吹走目录,并必须执行一个git克隆?


当前回答

下面的命令不会总是工作。如果你这样做了:

$ git checkout thebranch
Already on 'thebranch'
Your branch and 'origin/thebranch' have diverged,
and have 23 and 7 different commits each, respectively.

$ git reset --hard
HEAD is now at b05f611 Here the commit message bla, bla

$ git pull
Auto-merging thefile1.c
CONFLICT (content): Merge conflict in thefile1.c
Auto-merging README.md
CONFLICT (content): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.

等等……

要真正从头开始,下载分支并覆盖所有本地更改,只需执行:


$ git checkout thebranch
$ git reset --hard origin/thebranch

这就可以了。

$ git checkout thebranch
Already on 'thebranch'
Your branch and 'origin/thebranch' have diverged,
and have 23 and 7 different commits each, respectively.

$ git reset --hard origin/thebranch
HEAD is now at 7639058 Here commit message again...

$ git status
# On branch thebranch
nothing to commit (working directory clean)

$ git checkout thebranch
Already on 'thebranch'

其他回答

这对我很有效

git fetch --all
git reset --hard origin/master
git pull origin master

对于接受的答案,我会得到冲突错误

虽然很晚了,但有人会觉得这很有用。(为我工作过)

git restore < fileName>或git restore。 git拉

此外,还可以保留来自本地提交的更改,并将其作为新的提交推送。当我在本地提交中出现混乱时,我使用这些步骤。

git reset --soft origin/main git 存储 git pull --rebase 去藏匿流行音乐

git fetch --all && git reset --hard origin/master

. gitignore

“向.gitignore添加不需要的文件,只要你最初没有将它们提交给任何分支。”

你也可以运行:

git update-index --assume-unchanged filename

https://chamindac.blogspot.com/2017/07/ignoring-visual-studio-2017-created.html