为什么 `git add .` 命令有时不会将锁定文件添加到暂存区?

huangapple go评论106阅读模式
英文:

Why `git add . ` command sometimes doesn't adds lockfile to staging area?

问题

当我在使用pnpm的monorepo中执行git add .时,有时它不会将锁定文件包含到暂存区域中。

英文:

When I do git add . in a monorepo with pnpm, sometimes it doesn't include lockfile to staging area.

为什么 `git add .` 命令有时不会将锁定文件添加到暂存区?

答案1

得分: 2

确保在项目的根目录中运行 git add .,以便Git可以遍历文件树并暂存更改。

确保不要将锁定文件添加到 .gitignore 文件中,git add 命令在暂存更改时会尊重该文件。

使用 git add -A 而不是 git add .,以将仓库中最近提交后引入的所有更改添加到暂存区,而不仅仅是暂存当前目录中的更改。

英文:

Make sure to run the git add . from the root of the project such that git can parse through the file tree and stage the changes.

Make sure to not have lock file to the .gitignore file which git add commands respect when staging changes.

Use git add -A instead of git add . to add all the changes introduced after the recent commit in the repository instead of just staging changes in the current directory.

答案2

得分: 0

我遇到这个问题已经有一年了,当我提出这个问题时,我意识到了问题所在。对于其他人遇到这个问题的人,这里是问题的解决方法。

所以,这个项目是一个pnpm的monorepo,我在使用vscode工作区,所以它会在monorepo中的项目目录内打开我的终端。

-monoreporoot 
 |-apps
    |-project_1
 |-pnpm-lock.yaml

当我在那个项目上添加一个依赖时,它会更改项目根目录上的锁定文件。但是我在monoreporoot/apps/project_1目录上运行git add .。所以原来git add .是将你所在路径上的所有更改添加到版本库,而不是将所有更改添加到git仓库。这似乎很明显,但他们教我们这个命令会将所有更改添加到仓库中,我再也没有考虑过这个问题。

英文:

I had this problem for a year and I realized what was wrong while asking this question. Here is the problem for anyone else who encounters it.

So the project is a pnpm monorepo and I'm using vscode workspace so it opens my terminal inside of a project directory in monorepo.

-monoreporoot 
 |-apps
    |-project_1
 |-pnpm-lock.yaml

When I add a dependency on that project it changes the lockfile on the project root. But I'm doing git add . on monoreporoot/apps/project_1 directory. So it turns out that git add . is adding all changes in the path you are on not the all changes in the git repository. It's quite obvious but they taught us this command adds all changes to the repository and I never think about it again.

huangapple
  • 本文由 发表于 2023年8月10日 14:43:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76873180.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定