0

I made some modifications in the myproject_app/vendor/laravel/ui/auth-backend/AuthenticatesUsers.php; then I pushed the modifications with other files. When I tried to make git pull then I got error :

error: Your local changes to the following files would be overwritten by merge:
        myproject_app/vendor/laravel/ui/auth-backend/AuthenticatesUsers.php
Please commit your changes or stash them before you merge.
Aborting

So how to fix it ? I tried to add tokenlite_app/vendor/laravel/ui/auth-backend/AuthenticatesUsers.php in the .gitignore file which I pushed after receiving the error, but got same results

pheromix
  • 18,213
  • 29
  • 88
  • 158
  • 2
    you should never modify vendor files. you can discard the changes of that file and pull – kris gjika Jul 27 '23 at 07:33
  • how can I discard the changes given that I already made git commit and pushed ? – pheromix Jul 27 '23 at 07:36
  • 1
    are you sure you pushed `vendor` usually that whole folder should be in gitignore? If you did you should restore the vendor to the normal state first. Run `composer update` and push, this should revert your changes to vendor files. – kris gjika Jul 27 '23 at 07:41
  • it is the first time that I modified vendor files. So I will try your suggestion about composer update – pheromix Jul 27 '23 at 07:45
  • The error still appeared even after launching `composer update` – pheromix Jul 27 '23 at 08:04
  • completely delete your `vendor` and run `composer update` you should neither commit or modify the vendor, if you want to modify its behaviour you should override the methods. also add `vendor` to your gitignore – Salam Jul 27 '23 at 08:12
  • is it on my local repository that the `composer update` and deletion of the vendor folder should be made or at the remote repository ? – pheromix Jul 27 '23 at 08:19
  • Why did you modify and COMMIT a vendor file? The recommendation is not "you should not modify them", the recommendation is "NEVER modify AND commit them", always use another mechanicsm like forking and publishing your changes or make it local with a path. You have to `git rm PATH TO THE VENDOR FILE` so you remove the file from Git and can continue updating and stuff – matiaslauriti Jul 27 '23 at 10:38

2 Answers2

1

In most cases, the message Git provides is more than enough to solve the issue you are facing in the git.

"Please commit your changes or stash them before you merge."

Seeing the error the file vendor/laravel/ui/auth-backend/AuthenticatesUsers.php is still being modified either restore it back using

git checkout vendor/laravel/ui/auth-backend/AuthenticatesUsers.php

or

git restore <file>

You can just commit that file if you really need to update it, but vendor files should not be updated directly, it is better to fork if you are really in desperate need to update it. Or check if the package has some publish mechanism.

Deleting the vendors and such will not work since you have already pushed the vendor to the repo and doing composer install/update will just generate a new one which you need to again commit and push the new vendors and merge that, with the chance of merge conflicts if multiple developers are working on that repo.

Also, if you have already pushed the files to the repo, ignoring it afterwards is not simple like just adding that file path to .gitignore, you will need to follow a few more steps after adding on the .gitignore. Follow this Stackoverflow question for more info https://stackoverflow.com/a/1139797/8630903

Anuj Shrestha
  • 966
  • 6
  • 18
  • when I made `git restore myproject/.../AuthenticatesUsers.php` then I get filespec error that the file is not known by git – pheromix Jul 27 '23 at 09:08
  • @pheromix from which path you are executing the git commands? the root folder should not be in the file path "myproject" – Anuj Shrestha Jul 27 '23 at 09:09
  • finally I made git reset --hard then I run composer update – pheromix Jul 27 '23 at 11:53
  • @pheromix that works too it does revert your local repo to the last HEAD and revert everything back. So doing hard reset is always regarded as the final options for your case `git restore` or `git checkout` is the prefer command not hard reset – Anuj Shrestha Aug 01 '23 at 05:21
0

After googling I made a git reset --hard, then I made composer update.

pheromix
  • 18,213
  • 29
  • 88
  • 158