git - 无法 checkout 、 stash 或提交的文件

标签 git

我正在尝试git pull但我得到:

error: Your local changes to the following files would be overwritten by merge: database.sqlite3 Please, commit your changes or stash them before you can merge.

我试过git checkout database.sqlite3git stash甚至 git add -A但这个文件仍然存在。在 git add -A这家伙同时坐在暂存文件和未暂存文件上:

# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   database.sqlite3
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   database.sqlite3

有什么想法吗?

最佳答案

如果您想提交文件,请执行以下操作:

git commit -m 'database.sqlite3  changes' 
git add database.sqlite3
git commit -m 'database.sqlite3 more changes'
git push origin [branch-name]

该文件已更改两次,因此需要提交暂存的database.sqlite3。那么当前未上演的更改需要单独提交。

如果您想删除文件中的更改,请执行以下操作:

git checkout database.sqlite3
git reset
git checkout database.sqlite3

上面重复了 checkout 步骤,因为您需要删除两项更改。为了达到您所处的状态,您可能更改了一个文件,添加了它,然后再次更改了它。这就是为什么您必须撤消两项更改。

在上述任一情况之后,您应该能够执行 git pull。

关于git - 无法 checkout 、 stash 或提交的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30329320/

相关文章:

git - Bitbucket Cloud 中的级联 merge

git - 在 git revert 后取回更改并移动到单独的分支

git:显示默认/配置的寻呼机命令

Git 失败并显示 "fatal: protocol error: bad line length character: Pass"

git - 如何解析 "git show"输出?

java - Perforce值得吗?

python - 如何强制 Django 每次重新创建 .pyc 文件?

swift - 如何备份 Xcode 项目中的所有更改?

git - 如何自动检测 Git 提交或 rebase 是否包含类似 "<<<<< HEAD"的内容?

git - 如何截断 git log 中的字段 --pretty