text Git清理存储库

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text Git清理存储库相关的知识,希望对你有一定的参考价值。

# empty the stash
$ git stash clear

# objects can also be reached through the reflog. 
# while branches record the history of some project, reflogs record the history of these branches. 
# if you amend, reset etc. commits are removed from the branch history 
# but git keeps them around in case you realize that you made a mistake. 
# reflogs are a convenient way to find out what destructive (and other) operations were performed 
# on a branch (or HEAD), making it easier to undo a destructive operation.

# we also have to remove the reflogs to actually remove everything not reachable from a branch.
# we do so by expiring --all reflogs. 

# again git keeps a bit of the reflogs to protect users 
# so we again have to tell it not to do so: --expire-unreachable=now.
# use the reflog to recover from destructive operations 
# use --expire=now instead, which zaps the reflogs completely.
$ git reflog expire --expire-unreachable=now --all

# git-fsck - verifies the connectivity and validity of the objects in the database
# '--unreachable' print out objects that exist but that aren’t reachable from any of the reference nodes.
$ git fsck --unreachable

# removes unreachable objects (commits, trees, blobs (files)). 
# an object is unreachable if it isn't part of the history of some branch. 
# actually it is a bit more complicated;

# unreachable objects that are younger than two weeks are not removed 
# so we use --prune=now which means "remove unreachable objects that were created before now"
$ git gc --prune=now

以上是关于text Git清理存储库的主要内容,如果未能解决你的问题,请参考以下文章

清理git存储库

vscode 用git 拉取代码,提示:在签出前,请清理存储库工作树。请问是啥问题,如何解决。

text 更改GIT存储库的“origin”

text 清除git / github存储库历史的步骤

text 还原本地git存储库中的文件权限更改

text 本地git存储库的post-commit