如何只在本地保留所有项目的最新 git 提交?
How do I keep only the latest git commit locally for all of my projects?
我想在我的机器上释放一些 space 并且我的 git 历史变得相当大。我有大约 20 个项目,其中我将完整的历史推送到 GitHub,所以我只需要在我的机器上保留最新的提交。
我的两个问题是:
如何从项目中删除除最新提交之外的所有提交,但仅限于本地?我想在 GitHub 上保留所有历史记录,并在将来推送新的提交。
Linux 中的命令行脚本如何遍历我的项目文件夹并重复仅保留每个项目的最新提交的操作。这是我的项目文件夹结构:
GWDG+mschmidh@UG-UFBW100-C393 MINGW64 /p/r/projects
$ ls
be-a-mapper/
biogeochem-processes/
climathur/
coding/
coding-examples/
非常感谢您的帮助!
您要搜索的是git clone --depth 1
--depth
Create a shallow clone with a history truncated to the specified number of commits. Implies --single-branch unless --no-single-branch
is given to fetch the histories near the tips of all branches. If you
want to clone submodules shallowly, also pass --shallow-submodules.
所以只需 git clone --depth 1 https://github.com/mypersonal/repo
并且您的 .git 文件夹应该更小。
我想在我的机器上释放一些 space 并且我的 git 历史变得相当大。我有大约 20 个项目,其中我将完整的历史推送到 GitHub,所以我只需要在我的机器上保留最新的提交。
我的两个问题是:
如何从项目中删除除最新提交之外的所有提交,但仅限于本地?我想在 GitHub 上保留所有历史记录,并在将来推送新的提交。
Linux 中的命令行脚本如何遍历我的项目文件夹并重复仅保留每个项目的最新提交的操作。这是我的项目文件夹结构:
GWDG+mschmidh@UG-UFBW100-C393 MINGW64 /p/r/projects
$ ls
be-a-mapper/
biogeochem-processes/
climathur/
coding/
coding-examples/
非常感谢您的帮助!
您要搜索的是git clone --depth 1
--depth
Create a shallow clone with a history truncated to the specified number of commits. Implies --single-branch unless --no-single-branch
is given to fetch the histories near the tips of all branches. If you want to clone submodules shallowly, also pass --shallow-submodules.
所以只需 git clone --depth 1 https://github.com/mypersonal/repo
并且您的 .git 文件夹应该更小。