Git 添加修改后的文件不起作用,除了 -p(补丁)

Git add on modified file not working, except with -p (patch)

突然开始工作两个小时后,我似乎无法 git add 一个文件。

Casper@PC2015 MINGW64 /c/Workspace/edoping (develop)
$ git add .

Casper@PC2015 MINGW64 /c/Workspace/edoping (develop)
$ git status
    On branch develop
Your branch is up-to-date with 'origin/develop'.
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:   app/Http/Controllers/API/AuthController.php

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

我试了很多方法添加都没有成功:


所以我也检查了我是否有子模块(我不知道)。我似乎也没有。 为了找到它们,我做了:


我也查看了 .gitignore 文件,但这仍然是 Laravel 5.3

的默认值 .gitignore

git diff 像正常一样显示对文件所做的更改

Casper@PC2015 MINGW64 /c/Workspace/edoping (develop)
$ git diff
diff --git a/app/Http/Controllers/API/AuthController.php b/app/Http/Controllers/API/AuthController.php
index 9bfe453..5add519 100644
--- a/app/Http/Controllers/API/AuthController.php
+++ b/app/Http/Controllers/API/AuthController.php
@@ -65,7 +65,12 @@ class AuthController extends \App\Http\Controllers\Controller {
     public function register(Request $request) {

         $this->validate($request, [
-            'email' => 'unique:users,email'
+            'email'      => 'unique:users,email',
+            'first_name' => 'required|min:2|max:255',
+            'last_name'  => 'required|min:2|max:255',
+            'password'   => 'required|min:2|max:255',
+            'avatar'     => 'required',
+            'birthdate'  => 'required',
         ]);

.gitattributes 与 Laravel 默认值没有任何不同。

* text=auto
*.css linguist-vendored
*.scss linguist-vendored

没有嵌套的存储库:

Casper@PC2015 MINGW64 /c/Workspace/edoping (develop)
$ find -name .git
./.git

git add -p 给我以下输出。

Casper@PC2015 MINGW64 /c/Workspace/edoping (develop)
$ git add -p
diff --git a/app/Http/Controllers/API/AuthController.php b/app/Http/Controllers/API/AuthController.php
index 9bfe453..5add519 100644
--- a/app/Http/Controllers/API/AuthController.php
+++ b/app/Http/Controllers/API/AuthController.php
@@ -65,7 +65,12 @@ class AuthController extends \App\Http\Controllers\Controller {
     public function register(Request $request) {

         $this->validate($request, [
-            'email' => 'unique:users,email'
+            'email'      => 'unique:users,email',
+            'first_name' => 'required|min:2|max:255',
+            'last_name'  => 'required|min:2|max:255',
+            'password'   => 'required|min:2|max:255',
+            'avatar'     => 'required',
+            'birthdate'  => 'required',
         ]);

         $request->only($this->user_fillable);
Stage this hunk [y,n,q,a,d,/,j,J,g,e,?]?

当用 y 响应时,文件会添加到索引中。


为什么 git add -p 有效,而上述所有其他方法都无效?

编辑: 所以我尝试再次提交一些更改,但我确实发现了一些新东西。 Git似乎认为app/Http/Controllers/里面有两个文件夹,分别是ApiAPI。但是只有API.

大约一千次提交后,我确实将文件夹名称从 Api 更改为 API,因为我不得不从我的学长那里更改。这可能是问题的根源吗?

Casper@PC2015 MINGW64 /c/Workspace/edoping (develop)
$ gs
On branch develop
Your branch is up-to-date with 'origin/develop'.
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:   app/Http/Controllers/API/AuthController.php
        modified:   app/Http/Controllers/Api/AuthController.php

在尝试了很多不同的事情之后,我能够添加更改。

我做了什么:

  • git add -p 将输出提示。
  • Stage this hunk [y,n,q,a,d,/,K,j,J,g,e,?]?.
  • 我对每个更改都回答了 y,并在文件末尾添加了它。
  • 在此之后,我能够 commitpush 进行更改。

感谢大家的帮助,感谢 @mkrieger1git add -p

一起来