You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

git add * 是什么?与git add . 的区别及相关问题咨询

Hey there! Let's break down exactly what git add * does, how it differs from git add ., and why it might have fixed that push error you ran into.

What is git add *?

First off, git add * doesn’t let Git handle the wildcard directly—your shell (like Bash, Zsh, or PowerShell) expands the * before Git even gets involved. The shell will match all non-hidden files and folders in your current working directory (so anything that doesn’t start with a .) and pass those specific paths to Git. Git then stages those files/folders as requested.

A quick side note: If your shell has the dotglob option turned on (some setups enable this by default), * will also include hidden files—but that’s not the standard behavior for most shells.

Key Differences Between git add * and git add .

Let’s walk through the most important contrasts:

  • Hidden file handling: This is the big one. git add . tells Git to recursively stage every file in the current directory, including hidden ones (like .gitignore, .env, or .gitattributes), while respecting your .gitignore rules. git add * (by default) skips all hidden files entirely because the shell doesn’t expand * to include them.
  • How paths are processed: git add . lets Git do the directory traversal itself. It scans every file in the current directory and subdirectories, automatically skipping anything excluded by .gitignore. With git add *, the shell does the path matching first—Git only processes the paths the shell hands it, still applying .gitignore to those paths, but it won’t see hidden files unless the shell explicitly includes them.
  • Special character handling: If you have files with spaces or special characters in their names, git add . handles them flawlessly because Git parses the directory structure directly. git add * relies on the shell to properly quote or escape those characters, which works in most modern shells but can cause headaches in older environments (like Windows Command Prompt).
Why Might git add * Have Fixed Your Push Error?

Without seeing the exact error message, here are the most plausible scenarios:

  • Hidden files were causing conflicts: Maybe you accidentally staged a hidden file (like a local .env with personal credentials) that other developers didn’t have in their repos. Using git add * would exclude that hidden file from your staging area, so when you committed and pushed, there was no conflict over that file.
  • Staging area had inconsistencies: Sometimes, the staging area can get into a wonky state—for example, some tracked files were modified but not fully staged, or marked for deletion but not updated. Running git add * re-stages all non-hidden tracked files, fixing those inconsistencies that were blocking your push.
  • Misconfigured .gitignore edge case: If your .gitignore was accidentally targeting a directory that contained necessary non-hidden files, git add * might have bypassed that by directly targeting the files (though Git still applies .gitignore rules to these paths—this is a rarer scenario).

As a general rule of thumb, git add . is usually the safer go-to for staging all your changes (including hidden files) while honoring your ignore rules. git add * is more of a niche tool—use it when you specifically want to exclude hidden files from your staging area.

内容的提问来源于stack exchange,提问作者creator

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 10:17:14