git 还原实际未更改的文件夹
git restore of an actually unchanged folder
我有一个修改过的文件夹(为什么,我想不出任何机会)并想取消暂存(并保留)它的内容,因为它是一个子模块,里面有代码。
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 回购,后来 集成 到 MainProject 中。
子项目有一个自己的 .git
文件夹,因为每次编译整个项目时它总是抱怨未跟踪更改。
所以我删除了 SubProject 中的 .git
文件夹,并通过 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
总结:我假设我只添加了 SubProject 而不是 t-o-g-e-t-h-e-r 和 MainProject。
我有一个修改过的文件夹(为什么,我想不出任何机会)并想取消暂存(并保留)它的内容,因为它是一个子模块,里面有代码。
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 回购,后来 集成 到 MainProject 中。
子项目有一个自己的 .git
文件夹,因为每次编译整个项目时它总是抱怨未跟踪更改。
所以我删除了 SubProject 中的 .git
文件夹,并通过 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
总结:我假设我只添加了 SubProject 而不是 t-o-g-e-t-h-e-r 和 MainProject。