How can I remove all files in my git repo and update/push from my local git repo?

后端 未结 14 1899
猫巷女王i
猫巷女王i 2021-01-29 20:20

Is it possible to remove all files in a repository and update it with only the files I have in my local machine? The reason is that, there are certain files that is not necessar

相关标签:
14条回答
  • 2021-01-29 21:13

    Do a git add -A from the top of the working copy, take a look at git status and/or git diff --cached to review what you're about to do, then git commit the result.

    0 讨论(0)
  • 2021-01-29 21:14

    First of all, Navigate to your Folder using cd ( change directory) command. Then make sure you are in the correct git branch which you want to work by using the command

    git branch
    

    If you want to delete the entire files. you can do the same by using

    git rm -r .

    for deleting a single file,

    git rm file1.txt ( file1.txt - file Name )

    for delete a folder,

    git rm -r foldername

    After deleting the files or folders, you should commit it:

    git commit -m "your comment"
    

    Then you can push the branch:

    git push
    // for example, 
    git push origin develop
    

    (it will update the origin repository)

    0 讨论(0)
  • 2021-01-29 21:15

    I have tried like this

    git rm --cached -r * -f
    

    And it is working for me.

    0 讨论(0)
  • 2021-01-29 21:16

    Yes, if you do a git rm <filename> and commit & push those changes. The file will disappear from the repository for that changeset and future commits.

    The file will still be available for the previous revisions.

    0 讨论(0)
  • 2021-01-29 21:16

    You could do it like this:

    cd /tmp
    git clone /your/local/rep  # make a temp copy
    cd rep
    git rm -r *                # delete everything
    cp -r /your/local/rep/* .  # get only the files you want
    git add *                  # add them again
    git status                 # everything but those copied will be removed
    git commit -a -m 'deleting stuff'
    cd /your/local/rep
    git pull /tmp/rep          # now everything else has been removed
    

    There's probably a oneliner for that…

    0 讨论(0)
  • 2021-01-29 21:21

    Remove all files not belonging to a repositiory (e.g. for a clean-build after switching a branch):

     git status | xargs rm -rf
    
    0 讨论(0)
提交回复
热议问题