不论是 Windows 系统,还是 macOS 系统,我们总是能够碰见相关的本地设置配置文件或临时文件,而这些配置文件是我们不需要的,例如 Thumbs.db 或者 .DS_Store 文件,这些文件我们不需要上传到 Github 之上。

移除方法

移除这些临时文件到方法步骤基本上是一致到:

  1. 先 Clone 仓库到本地;
  2. 找到或创建 .gitignore 文件;
  3. 配置本地的 .gitignore 文件;
  4. 删除本地已经存在的 “无用” 文件;
  5. 提交上传即可。

1. Clone 仓库到本地

当我们 Clone 到本地后,就可以开始配置 .gitignore 文件(如无新建)。

2. 找到或创建 .gitignore 文件

对于 Windows 系统,.gitignore 文件若存在,则会在仓库文件夹根目录下可以看见。对于 macOS 系统,.gitignore 文件默认隐藏,需要使用如下指令进行显化(需要重启 Finder):

// 显示隐藏文件
defaults write com.apple.finder AppleShowAllFiles -bool true

如果你想再次隐藏(需要重启 Finder):

// 再次隐藏文件
defaults write com.apple.finder AppleShowAllFiles -bool false

除此之外,你还可以参考 Apple macOS 使用手册中到 《在 Mac 上显示或隐藏文件扩展名》,查看详细方法。

3. 配置本地的 .gitignore 文件

推荐一个常用的 .gitignore 文件配置:

# Windows image file caches
Thumbs.db
ehthumbs.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk

# =========================
# Operating System Files
# =========================

# OSX
# =========================

*/.DS_Store
.DS_Store
.AppleDouble
.LSOverride

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

这份配置文件,基本上排除了 Windows 系统下到缩略图临时文件,设置文件等信息,排除了 macOS 系统下文件夹配置文件等。

4. 删除本地已经存在的 “无用” 文件

打开 Terminal,使用 cd 命令 打开你需要删除无用文件的本地仓库文件夹。

再使用如下命令删除 .DS_Store 文件:

find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch

5. 提交上传即可

删除完成后,即可 commit 提交到云端。

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

Next Post

将自己网站的搜索功能加入到Chrome Tab中

周六 2 月 22 , 2020
在使用 Chrome 浏览器的时候,你肯定会发现, […]