开发者

can I empty a remote git repository?

开发者 https://www.devze.com 2023-01-24 10:23 出处:网络
I created new remote git repository and already pushed something in there - first test push and then real code push from local. I want to start from scratch so I can creat few branches (master = ready

I created new remote git repository and already pushed something in there - first test push and then real code push from local. I want to start from scratch so I can creat few branches (master = ready to release code, test branch and branches for developers) and give them different permissions per user.

Can I empty the existing remote repository somehow? It's a remote git repository that sits on linux and developer and I开发者_开发技巧 run windows box.


I don't think it is very useful, but you can restart the master branch (forgetting all history) by

rm .git/index .git/refs/heads/master
echo "Hello!" > README
git add README
git commit -m "Exterminate! Exterminate!"

and push to your remote repository. Usually I would just start over with an empty repository, add your remote repository and push from there.

Some explanation: The first line deletes the index (so your next commit won't contain any files) and the current pointer to the tip of the master branch (so your next commit won't be committed on top of any previous commit). In the second and third line, we add some content to our new repository and commit that content in the fourth line.


If you want the repo gone, just take it away! Delete the whole containing directory, and recreate it as you see fit.

Yes, you could also make a new repo just on your end, and force push to the remote, and remotely delete all the refs, and then make sure git gc gets run on it... but that takes time and effort. Just wipe it out.

0

精彩评论

暂无评论...
验证码 换一张
取 消