git add adding ignored files

后端 未结 10 2184
不知归路
不知归路 2021-02-01 00:58

I\'m trying to remove a previously tracked directory from git, which works, but it\'s being added back with each subsequent git add ., git add -A, etc.

10条回答
  •  臣服心动
    2021-02-01 01:48

    The origin has to be bare. Here is a little bash to demonstrate it. Feel free to edit it, if it does not represent your use case.

    #!/bin/bash
    
    rm -rf /tmp/git_test
    mkdir /tmp/git_test/
    git init --bare /tmp/git_test/primary_repo
    
    # populate repo
    cd /tmp/git_test/
    git clone ./primary_repo ./secondary_repo
    cd secondary_repo
    echo hi_bob > some_content
    mkdir node_modules
    echo hi_dave > node_modules/moduleA
    git add .
    git commit -m "populated primary"
    git push
    
    # do the removal in tertiary 
    cd /tmp/git_test/
    git clone ./primary_repo ./tertiary_repo
    cd tertiary_repo
    echo node_modules >> .gitignore
    git add .gitignore
    git rm -r --cached node_modules
    git commit -a -m "removed node_modules"
    git push origin master
    rm -r node_modules
    echo --------------------------------
    echo git status:
    git status
    

提交回复
热议问题