Search code examples
gitgit-submodules

git restore of an actually unchanged folder


I have a modified folder (whyever, I can't figure out any chances on it) and want to unstage (and keep) its content because it is a submodule here with codes inside.

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")

So far I know I can unstage it with git restore SubProject. If I say git restore SubProject I get still

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")

After a while of research I stuck with this problem. What am I doing wrong?


Solution

  • Edit: The first solution was just temporary. I got the same issue again working on this repo.

    Permanant solution: I figured out the SubProject was a former git repo which was integrated later into the MainProject.

    The SubProject had a .git folder by its own, since it was always complaining untracked changes for each time compiling the whole project.

    So I deleted .git folder in the SubProject and got the right status back checking with git status.

    I keep the temporary solution striked out (could be helpful for another one).

    Temporary solution: The solution was to add the folder to the main project.

    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
    

    And then I commited it pushed it to the 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
    

    Checking again with git status I got

    On branch master
    Your branch is up to date with 'origin/master'.
    
    nothing to commit, working tree clean
    

    Summary: I assume I only added the SubProject but not t-o-g-e-t-h-e-r with the MainProject.