-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Git删除某个文件的全部历史记录 | ||
|
||
注意:文本使用gpt帮助,本人实际验证。 | ||
|
||
|
||
使用 filter-branch 命令:下面的命令将删除指定文件的所有历史记录。 | ||
```shell | ||
|
||
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch <file_path>' --prune-empty --tag-name-filter cat -- --all | ||
``` | ||
|
||
在上面的命令中,<file_path> 应替换为你想要删除的文件的路径。 | ||
|
||
推送更改:一旦完成重写历史,你需要强制推送更改到远程仓库。 | ||
|
||
```shell | ||
git push origin --force --all | ||
``` | ||
|
||
请注意,这会覆盖远程仓库中的历史记录,确保你有权力这样做并且了解潜在的影响。 | ||
|
||
记住,这个操作会改变 Git 的历史记录,因此在团队环境中需要小心谨慎。最好是提前告知其他团队成员,并确保他们也执行相应的操作来更新他们的本地仓库。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters