Git add to the modified file does not work, except with -p (patch)

After the first two hours of work all of a sudden, I cannot submit git add single file.

 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") 

I tried a lot if ways to add without success:

  • git add .
  • git add <path-to-file>
  • git add -f <path-to-file>
  • git add --all
  • git commit -a

So, I also checked if I have submodules (which would know about it without me). And I also did not have such. To find them, I did:

  • git config --file .gitmodules --name-only --get-regexp path
  • grep path .gitmodules | sed 's/.*= //'
  • git submodule status --recursive .

I also looked at the .gitignore file, but this is still the default .gitignore from Laravel 5.3


git diff shows the changes made to the file as usual

 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 shows nothing but the default values โ€‹โ€‹of Laravel.

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

There are no nested repositories:

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

git add -p gives me the following result.

 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,?]? 

When y file is added to the index.


Why does git add -p and all the other methods described above do not work?

EDIT : So I tried again to make some changes, but found something new. Git seems to have two folders inside app/Http/Controllers/ , which are Api and Api . But there is only Api .

About a thousand recruits back, I changed the name of the folder from Api to Api , because I had to from my boss. Could this be the cause of the problem?

 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 
+6
source share
1 answer

Having tried many different things, I was able to add changes.

What I've done:

  • git add -p which will prompt.
  • Stage this hunk [y,n,q,a,d,/,K,j,J,g,e,?]? .
  • I answered y for each change and added at the end of the file.
  • After that I was able to commit and push to make changes.

Thanks everyone for the help and @ mkrieger1 for coming with git add -p

+4
source

Source: https://habr.com/ru/post/1015396/


All Articles