有没有办法做一个git pull
来忽略任何本地文件的更改,而又不浪费目录,也不必执行git clone
?
#1楼
如果您使用的是Linux:
git fetch
for file in `git diff origin/master..HEAD --name-only`; do rm -f "$file"; done
git pull
for循环将删除在本地存储库中更改的所有跟踪文件,因此git pull
可以正常工作。
最好的事情是,只有被跟踪的文件将被仓库中的文件覆盖,所有其他文件将保持不变。
#2楼
下面的命令永远不会起作用 。 如果您只是做:
$ 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'
#3楼
对我来说,以下工作:
(1)首先获取所有更改:
$ git fetch --all
(2)然后重置主机:
$ git reset --hard origin/master
(3)拉/更新:
$ git pull
#4楼
这将获取当前分支并尝试快速转发到master:
git fetch && git merge --ff-only origin/master
#5楼
查看git stash ,将所有本地更改放入“ stash文件”中,并还原到最后一次提交。 此时,您可以应用隐藏的更改,也可以将其丢弃。
来源:oschina
链接:https://my.oschina.net/stackoom/blog/3161816