【问题标题】:Checked out on master, brought changes to it and now cannot checkout back to branch在 master 上签出,对其进行了更改,现在无法签出回分支
【发布时间】:2021-05-15 08:51:18
【问题描述】:
git status
On branch master
Your branch is behind 'origin/master' by 10 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

 

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   Resources/Common/Ui-de.json
        modified:   Resources/Common/Ui-en.json
        modified:   Resources/Common/Ui-es.json
        modified:   Resources/Common/Ui-fr.json
        modified:   Resources/Common/Ui-nl.json

 

no changes added to commit (use "git add" and/or "git commit -a")

我在我的功能分支上进行更改,并看到这些文件更改被其他人修改。我提交了它们,然后在 master 上签出了。

问题是,在 master 分支上,这 5 个确切的更改仍然显示为未提交的更改,现在我无法结帐到我的其他分支,也无法从源中提取,因为它要求我先提交更改。但是,我不想直接在 master 上提交更改。再说一遍,这些更改不是我做的。

我已尝试存储和还原更改,但两者都不起作用,文件只是保留在那里。

这里到底发生了什么?我正在考虑将它们提交到 master 上而不进行推送,这样我就可以拉取并结帐到其他分支,并且永远不要将这些提交推送到 master 上,但这似乎不是最好的解决方案。

【问题讨论】:

  • 如果他们未提交,那么他们不在主人身上。本地 master 分支也不是最新的。
  • 查看变化。这似乎是您应该首先处理的行尾问题(您应该通过使用.gitattributes 文件来处理)。
  • 是的,我认为这是将 CLRF 更改为 LF 的问题,反之亦然。尽管在我的 gitattributes 中,所有内容都已设置为 CLRF。我只是想知道为什么我不能强制还原这些更改/提交。

标签: git version-control git-commit


【解决方案1】:

这就是解决办法!

git rm --cached -r .
git reset --hard

【讨论】:

  • 这就是蛮力方法(简单易行,因此经常使用)。每当你在 Git 中开启 CRLF 转换功能时,都会进入这样的怪异状态。
猜你喜欢
  • 2021-07-27
  • 2012-07-03
  • 1970-01-01
  • 2015-02-01
  • 2018-05-14
  • 2021-12-27
  • 2015-11-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多