git - git restore 一个实际未更改的文件夹
问题描述
我有一个修改过的文件夹(但是,我想不出任何机会)并且想要取消暂存(并保留)其内容,因为它是这里的子模块,里面有代码。
C:\Users\devuser\source\repos\MainProject>git status
On branch master
Your branch is up to date with 'origin/master'.
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: SubProject (new commits)
no changes added to commit (use "git add" and/or "git commit -a")
到目前为止,我知道我可以使用git restore SubProject
. 如果我说git restore SubProject
我静下来
C:\Users\devuser\source\repos\MainProject>git status
On branch master
Your branch is up to date with 'origin/master'.
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: SubProject (new commits)
no changes added to commit (use "git add" and/or "git commit -a")
经过一段时间的研究,我遇到了这个问题。我究竟做错了什么?
解决方案
编辑:第一个解决方案只是暂时的。我在这个 repo 上再次遇到了同样的问题。
永久解决方案:我发现这SubProject
是一个以前的 git repo,后来被集成到 MainProject 中。
SubProject 有.git
自己的文件夹,因为每次编译整个项目时它总是抱怨未跟踪的更改。
所以我删除.git
了 SubProject 中的文件夹,并通过git status
.
我保留了临时解决方案(可能对另一个解决方案有帮助)。
临时解决方案:
解决方案是将文件夹添加到主项目。
C:\Users\devuser\source\repos\MainProject>git add SubProject
C:\Users\devuser\source\repos\MainProject>git add SubProject/
C:\Users\devuser\source\repos\MainProject>git status
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: SubProject
然后我将其提交到 repo。
C:\Users\devuser\source\repos\MainProject>git commit -m "SubProject was unstaged?!"
[master 1042efc] SubProject was unstaged?!
1 file changed, 1 insertion(+), 1 deletion(-)
C:\Users\devuser\source\repos\MainProject>git push
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 266 bytes | 266.00 KiB/s, done.
Total 2 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Analyzing objects... (2/2) (196 ms)
remote: Storing packfile... done (54 ms)
remote: Storing index... done (48 ms)
To https://my.repo.com/DefaultCollection/MainProject/_git/MainProject
b901854..1042efc master -> master
再次检查git status
我得到了
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
摘要:我假设我只添加了子项目,但没有与 MainProject 一起添加。
推荐阅读
- c# - 如何通过选择另一个 ListView 中的项目来显示 ListView 中的元素?
- linux - Bash shell 脚本,如何在命令中使用管道
- android - 如何使用 JSON API 在 recyclerview 滚动上加载更多数据
- javascript - App Lab 的 readRecords() 更改元素的 ID
- python - NumPy:根据另一个掩码屏蔽数组
- tensorflow - 我的验证损失低于我的训练损失,我应该摆脱正则化吗?
- asp.net-core-2.0 - 在 ASP.NET Core 2.2 应用程序中安装 Microsoft Extensions 包 3.1
- android - 如何检查变量值是否在 Kotlin 的其他线程中更改?
- python - 如果不同的列满足熊猫中的条件,如何从组中删除所有行
- vue.js - Vue.js:如何使转换组只触发一次?