Git commit正在我的repo中暂存所有其他文件

时间:2018-02-12 20:29:51

标签: git version-control

我遇到了一个git问题,每次提交,无论播放什么文件,都会在repo中添加并提交所有已更改的文件。

我正在使用VS Code和Git Bash。在这两种环境中都存在同样的问题。这与我专门上演的文件无关。

操作系统:Windows vsCode:1.20.0 壳牌1.7.9 git:2.16.1.4-64x

我有:

  • 卸载并重新安装git bash。
  • 手动添加文件并通过Git Bash提交。 git add ./filename.example git commit -m "commit message"
  • 尝试使用VSCode的提交暂存选项。
  • 看着我的.gitconfig。只有涉及http:sslVerify,用户设置,difftool和mergetool的标准设置被设置为sourcetree。
  • VScode设置(选中“git.enableSmartCommit”:false)。

在VS代码未运行的Git Bash中暂存和提交的示例:

Comp-NZ:  ~/Workspace/Project  |master ✓|
→ git status
On branch master
Your branch is behind 'origin/master' by 1 commit, and can be fast-
forwarded.
  (use "git pull" to update your local branch)

Changes not staged for commit:
 (use "git add <file>..." to update what will be committed)
 (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   frontend/src/app/app.component.ts
    modified:   frontend/src/app/globals.service.ts

no changes added to commit (use "git add" and/or "git commit -a")

Comp-NZ:  ~/Workspace/Project  |master ↓1 U:2 ✗|
→ git add ./frontend/src/app/app.component.ts
warning: LF will be replaced by CRLF in frontend/src/app/app.component.ts.
The file will have its original line endings in your working directory.

Comp-NZ:  ~/Workspace/Project  |master ↓1 S:1 U:1 ✗|
→ git status
On branch master
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
 (use "git pull" to update your local branch)

Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

modified:   frontend/src/app/app.component.ts

Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified:   frontend/src/app/globals.service.ts

Comp-NZ:  ~/Workspace/Project  |master ↓1 S:1 U:1 ✗|
→ git commit -m "test commit"
backend\src\app.controller.ts 176ms
backend\src\app.module.ts 6ms
backend\src\database\database.module.ts 7ms
backend\src\database\database.tokens.ts 1ms
backend\src\database\models\index.ts 0ms
backend\src\main.ts 10ms
frontend\e2e\app.e2e-spec.ts 5ms
frontend\e2e\app.po.ts 3ms
frontend\src\app\app.component.ts 11ms
frontend\src\app\app.module.ts 8ms
frontend\src\app\app.routing.module.ts 8ms
frontend\src\app\approval\approval.component.spec.ts 6ms
frontend\src\app\approval\approval.component.ts 4ms
frontend\src\app\auth.config.ts 3ms
frontend\src\app\core\core.module.ts 2ms
frontend\src\app\globals.service.spec.ts 4ms
frontend\src\app\globals.service.ts 2ms
frontend\src\app\globals.ts 0ms
frontend\src\app\home\app.component.spec.ts 6ms
frontend\src\app\home\home.component.ts 2ms
frontend\src\app\login\login.component.spec.ts 6ms
frontend\src\app\login\login.component.ts 5ms
frontend\src\app\mission-overview\mission-overview.component.spec.ts 6ms
frontend\src\app\mission-overview\mission-overview.component.ts 11ms
frontend\src\app\missions\missions.component.spec.ts 5ms
frontend\src\app\missions\missions.component.ts 2ms
frontend\src\app\request-channels\request-channels.component.spec.ts 9ms
frontend\src\app\request-channels\request-channels.component.ts 4ms
frontend\src\app\shared\app-material.module.ts 3ms
frontend\src\app\shared\mission-status\mission-status.component.spec.ts 4ms
frontend\src\app\shared\mission-status\mission-status.component.ts 4ms
frontend\src\app\shared\shared.module.ts 2ms
frontend\src\app\validation\validate.component.spec.ts 5ms
frontend\src\app\validation\validate.component.ts 2ms
frontend\src\main.ts 2ms
frontend\src\polyfills.ts 5ms
frontend\src\test.ts 3ms
frontend\src\typings.d.ts 2ms

warning: LF will be replaced by CRLF in frontend/src/app/globals.service.ts.
The file will have its original line endings in your working directory.
[master d19bf0c] test commit
 2 files changed, 5 insertions(+), 1 deletion(-)

Comp-NZ:  ~/Workspace/Project  |master ↑1 ↓1 ✓|
→ git status
On branch master
Your branch and 'origin/master' have diverged,
and have 1 and 1 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

nothing to commit, working tree clean

Comp-NZ:  ~/Workspace/Project  |master ↑1 ↓1 ✓|

3 个答案:

答案 0 :(得分:0)

创建一个文件&#34; .gitignore&#34;并添加GIT应忽略的所有文件或导演。

.gitignore in directory

示例:

.settings/org.eclipse.wst.common.project.facet.core.xml
.settings/org.eclipse.wst.common.project.facet.core.prefs.xml
.settings/org.eclipse.wst.common.project.facet.core.xm
**/pom.properties
/target/

有关详细信息,请参阅documentation

答案 1 :(得分:0)

git commit不应提交非暂存文件。您可以使用以下方式提交特定文件:

git add ./frontend/src/app/app.component.ts
git commit -m "test commit" ./frontend/src/app/app.component.ts   

答案 2 :(得分:0)

修复:我发现了问题...... Git挂钩。 Git Hooks是Git在事件之前或之后执行的脚本。它们位于repo的项目/ .git / hooks文件夹中。 &#39;预先提交&#39;钩似乎干涉我的git save。 钩子如下:

#!/bin/bash
./node_modules/pre-commit/hook
RESULT=$?
[ $RESULT -ne 0 ] && exit 1
exit 0

然后重定向到此包:https://www.npmjs.com/package/pre-commit

问题来自./node_modules/pre-commit/hook ln:49

"$BINARY" "$("$BINARY" -e "console.log(require.resolve('pre-commit'))")"