简体   繁体   中英

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

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 necessary in my github and so I want to remove those files. Instead of removing the files one by one, I wanted to see if its possible to just remove all files in my git repo and update/push with only the files in my local machine. Hope its clear. Thanks.

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…

First, remove all files from your Git repository using: git rm -r *

After that you should commit: using git commit -m "your comment"

After that you push using: git push (that's update the origin repository)

To verify your status using: git status

After that you can copy all your local files in the local Git folder, and you add them to the Git repository using: git add -A

You commit ( git commit -m "your comment" and you push ( git push )

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.

Warning: this will delete your files, make sure you have a backup or can revert the commit.

Delete all elements in repository:

$ git rm -r *

then:

$ git commit -m 'Delete all the stuff'

In my case

git rm -r .

made the job

This process is simple, and follows the same flow as any git commit.

  1. Make sure your repo is fully up to date. (ex: git pull )
  2. Navigate to your repo folder on your local disk.
  3. Delete the files you don't want anymore.
  4. Then git commit -m "nuke and start again"
  5. Then git push
  6. Profit.

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)

I was trying to do :

git rm -r *

but at the end for me works :

git rm -r .

I hope it helps to you.

Delete all elements in repository:

 git rm -r * -f -q

then:

 git commit -m 'Delete all the stuff'

then:

 git push -u origin master

then:

 Username for : "Your Username" 
 Password for : "Your Password"

If you prefer using GitHub Desktop , you can simply navigate inside the parent directory of your local repository and delete all of the files inside the parent directory. Then, commit and push your changes. Your repository will be cleansed of all files.

从工作副本的顶部执行git add -A ,查看git status和/或git diff --cached以查看您将要执行的操作,然后git commit结果。

删除所有不属于存储库的文件(例如,切换分支后的干净构建):

 git status | xargs rm -rf

I have tried like this

git rm --cached -r * -f

And it is working for me.

Just running it, solved for me:

git rm -r --cached .
git add .
git commit -m "remove gitignore files"
git push

as answered here: https://stackoverflow.com/a/50675909/3294762

删除隐藏的.git文件夹(您可以在项目文件夹中找到该文件夹​​)并再次使用git init命令开始创建 git 存储库的过程。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM