美文网首页Git
Git "forget" already tracked fil

Git "forget" already tracked fil

作者: JaedenKil | 来源:发表于2022-05-10 16:54 被阅读0次

    Scenario: A project is initialized, add a .gitignore file with content .idea. But unfortunately the folder idea is already in the git repo, generate the .gitignore file later will not remove the folder from the repo.

    Solutions:

    1.

    Make sure the working space is clean

    $ git rm -r --cached .idea/
    rm '.idea/.gitignore'
    rm '.idea/UpdateTvtsPkg.iml'
    rm '.idea/dictionaries'
    rm '.idea/inspectionProfiles/Project_Default.xml'
    rm '.idea/inspectionProfiles/profiles_settings.xml'
    rm '.idea/misc.xml'
    rm '.idea/modules.xml'
    rm '.idea/vcs.xml'
    
    git add -u
    git commit -m "Update git ignored files/folders"
    git push
    

    2.

    Make sure the working space is clean

    # Remove all tracked files, including wanted and unwanted
    git rm -r --cached .
    
    # Add all the files/folders expect those in .gitignore
    git add .
    git commit -m "Update git ignored files/folders"
    git push
    

    .gitignore will prevent untracked files from being added (without an add -f) to the set of files tracked by Git. However, Git will continue to track any files that are already being tracked.

    WARNING: While this will not remove the physical file from your local machine, it will remove the files from other developers' machines on their next git pull.

    相关文章

      网友评论

        本文标题:Git "forget" already tracked fil

        本文链接:https://www.haomeiwen.com/subject/mdnlurtx.html