【发布时间】:2019-04-12 08:04:52
【问题描述】:
我在本地my-feature 分店
git status 举报nothing to commit, working tree clean
我想切换到开发分支并在那里做git fetch和git merge(我更喜欢它而不是git pull)
但是,这样做会产生以下错误
这里我首先检查状态,它表明一切都很干净
mymbp:MyProj username$ git status
On branch my-feature
nothing to commit, working tree clean
接下来我尝试检查我的开发分支,它是一个现有的本地分支
On branch my-feature
nothing to commit, working tree clean
mymbp:MyProj username$ git checkout develop
error: Your local changes to the following files would be overwritten by checkout:
MyProj.sln
Please commit your changes or stash them before you switch branches.
Aborting
它抱怨myProj.sln 已更改,即使git status 表示没有任何更改。
再次发出git status,确认没有任何变化
mymbp:MyProj username$ git status
On branch my-feature
nothing to commit, working tree clean
更新 1
执行git ls-files --stage --debug MyProj.sln 如下所示,我没有看到任何 4000 或 8000(--skip-worktree 或 --assume-unchanged 标志):
mymbp:MyProj username$ git ls-files --stage --debug MyProj.sln
100644 40c3593ed572beb2139c189455274f8900a1340c 0 MyProj.sln
ctime: 1541703970:521058155
mtime: 1541637062:121492660
dev: 16777220 ino: 8470003
uid: 501 gid: 20
size: 55684 flags: 0
mymbp:MyProj username$
发布git show develop:MyProj.sln 会显示解决方案中的项目文件数量及其 GUID,用于前后解决方案的全局部分,但输出很长,仅显示发布、调试配置和一些 GUID。还不知道该怎么处理。
更新 2
因此,似乎 MyProj.sln 文件在工作树中,但不在索引和提交 (HEAD) 中。根据@torek 的解释,发出 git add MyProj.sln 应该将此文件添加到索引中,但事实并非如此,因为没有添加任何内容,并且 git status 在我执行 git add 之前和之后都没有返回任何内容。同时 git checkout 仍然抱怨 MyProj.sln 已更改。 git diff 也不返回任何内容
更新 3
我还发现有人建议发出这 2 个命令来获取提交 HEAD 的哈希值,然后查看其中发生了什么变化。我看到很多文件重复,而有些则没有。那些似乎不是我在当前功能分支中添加的文件。那些重复的似乎是来自远程的文件
mymbp:MyProj username$ git rev-parse HEAD
1ca8d8a7c5eff0f2a03eb185f1b25aff27c1d2fd
mymbp:MyProj username$ git ls-tree -r 1ca8d8a7c5eff0f2a03eb185f1b25aff27c1d2fd
这是它的输出
更新 4
我的配置是:
mymbp:MyProj username$ git config --list
credential.helper=osxkeychain
core.excludesfile=/Users/username/.gitignore_global
core.autocrlf=input
difftool.sourcetree.cmd=opendiff "$LOCAL" "$REMOTE"
difftool.sourcetree.path=
mergetool.sourcetree.cmd=/Applications/Sourcetree.app/Contents/Resources/opendiff-w.sh "$LOCAL" "$REMOTE" -ancestor "$BASE" -merge "$MERGED"
mergetool.sourcetree.trustexitcode=true
user.name=User Name
user.email=username@somesystems.com
color.ui=true
color.status.changed=blue normal
color.status.untracked=red normal
color.status.added=magenta normal
color.status.updated=green normal
color.status.branch=yellow normal bold
color.status.header=white normal bold
commit.template=/Users/username/.stCommitMsg
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
core.ignorecase=true
core.precomposeunicode=true
remote.origin.url=https://github.com/SomeSystems/MyProj.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.develop.remote=origin
branch.develop.merge=refs/heads/develop
branch.feat-1.remote=origin
branch.feat-1.merge=refs/heads/feat/feat-1
branch.1234-refactoring.remote=origin
branch.1234-refactoring.merge=refs/heads/1234-refactoring
mymbp:MyProj username$
【问题讨论】:
-
文件
MyProj.sln真的被添加到当前分支了吗? -
另一个 git status 怎么说
-
它已经存在了几个月,但无论如何,即使添加了它,git status 也应该将其视为未跟踪。另一个 git 状态?每次我在这个分支中执行 git status 时,它说工作树是干净的,我重新启动并尝试了几次,每次结果都和上面一样
-
如果您有未跟踪的文件并且您收到该消息,可能是因为它已被添加到分支(由其他人?)。
-
不,这是我的本地功能分支,没有人碰过它。另外,该文件未显示为未跟踪。 Git status 显示没有任何变化, git commit 显示它已经如上文所述。我更新为 clerify
标签: git macos github git-checkout