本文共 2145 字,大约阅读时间需要 7 分钟。
If you feel the need to discard all your local changes and just reset/overwrite everything with a copy from the remote branch, then you should follow this guide.
如果您需要放弃所有本地更改,而只是使用远程分支的副本重置/覆盖所有内容,则应遵循本指南。
Important: If you have any local changes, they will be lost. With or without --hard
option, any local commits that haven’t been pushed will be lost.
重要提示:如果您进行任何本地更改,它们将会丢失。 无论是否使用--hard
选项,所有尚未推送的本地提交都将丢失。
If you have any files that are not tracked by Git (e.g. uploaded user content), these files will not be affected.
如果您有Git不能跟踪的任何文件(例如,上载的用户内容),这些文件将不会受到影响。
To overwrite your local files do:
要覆盖本地文件,请执行以下操作:
git fetch --allgit reset --hard/
For example:
例如:
git fetch --allgit reset --hard origin/master
git fetch
downloads the latest from remote without trying to merge or rebase anything.
git fetch
从远程下载最新版本,而无需尝试合并或重新设置任何内容。
Then the git reset resets the master branch to what you just fetched. The --hard
option changes all the files in your working tree to match the files in origin/master
.
然后git reset将master分支重置为您刚获取的分支。 --hard
选项更改工作树中的所有文件,以匹配origin/master
中的文件。
It’s worth noting that it is possible to maintain current local commits by creating a branch from master
or whichever branch you want to work on before resetting:
值得注意的是,可以通过在重置之前从master
或您要处理的任何分支创建分支来维护当前的本地提交:
For Example:
例如:
git checkout mastergit branch new-branch-to-save-current-commitsgit fetch --allgit reset --hard origin/master
After this, all of the old commits will be kept in new-branch-to-save-current-commits
. Uncommitted changes however (even staged), will be lost. Make sure to stash and commit anything you need.
在此之后,所有旧提交都将保存在new-branch-to-save-current-commits
。 但是,未提交的更改(即使已分阶段)将丢失。 确保隐藏并提交您需要的任何东西。
This article is based on a Stack Overflow question <a href=’’ target=’blank’ rel=‘nofollow’>here_
本文基于堆栈溢出问题<a href =' ://stackoverflow.com/questions/1125968/force-git-to-overwrite-local-files-on-pull/8888015#8888015'target ='空白'rel ='nofollow'>此处_
翻译自:
转载地址:http://iozzd.baihongyu.com/