Git 签出错误
我正在使用脚本自动检查过去 12 个月每个月的第一次提交。偶尔会发生一些奇怪的事情,我不再被允许检查过去的提交。错误如下所示:
错误:您对以下文件的本地更改将被签出覆盖:
db test/framework.cpp
请提交您的更改或者在切换分支之前将它们隐藏起来。中止
这种情况已经发生过很多次(我没有编辑任何文件,只是检查它们)。我通常只是从 Github 下载一个新的存储库副本,然后再次启动该过程,它就可以工作了。但一旦坏了,我不知道如何修复,而且这种情况不断发生。有什么想法吗?
这是我的脚本中进行的迭代,后面是 git status 的输出
for i in {12..1}
do
cd
cd git/mongodb/mongo
git checkout master
git checkout $(git rev-list --before "$(date -d "$(date +%Y-%m-01) -$i months 00:01" +%Y-%m)-01" -n 1 HEAD)
git checkout master
Git status:
Onbranch master
Changes not staged for commit:
modified: dbtests/framework.cpp
Untracked files:
SHA1.txt
SHA1.txt.
file
file.
nochanges added to commit
I am using a script to automatically checkout the first commit of each month, for the last 12 months. Occasionally something strange happens and I am no longer allowed to checkout past commits. The error goes something like this:
error: Your local changes to the following files wold be overwritten by checkout:
db tests/framework.cpp
Please, commit your changes or stash them before you can switch branches. Aborting
This has happened many times (I am not editing any files, just checking them out). I usually just download a fresh copy of the repo from Github and start the process again and it works. But once it breaks I don't know how to fix it, and it keeps happening. Any thoughts?
Here is the iteration going on in my script, followed by the output of git status
for i in {12..1}
do
cd
cd git/mongodb/mongo
git checkout master
git checkout $(git rev-list --before "$(date -d "$(date +%Y-%m-01) -$i months 00:01" +%Y-%m)-01" -n 1 HEAD)
git checkout master
Git status:
On branch master
Changes not staged for commit:
modified: dbtests/framework.cpp
Untracked files:
SHA1.txt
SHA1.txt.
file
file.
no changes added to commit
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
--force
标志让 Git 无论如何都进行签出。或者,您可以使用 git reset --hard 来重置提交,而不是使用签出。
You can use the
--force
flag to make Git do the checkout anyway.Alternatively, you could use
git reset --hard
instead to reset to the commits, rather than using checkout.2019+ 语法现在将使用新的
git switch
命令 (Git 2.23+) -f 是
--discard-changes
选项的别名:The 2019+ syntax would now be using the new
git switch
command (Git 2.23+)The -f is an alias for the
--discard-changes
option: