0

if relevant: Laravel. PHP 7.0.3

Hi! I had to delete 'vendor' folder in my project and do "composer install" to re-install all libraries. Then I modified some project's files (outside "/vendor").

git status

showed me not only my project files being modified, but all the files inside '/vendor' being deleted and then modified.

After

git add . && git status

shows all projects modified files and all files from "/vendor" in the list of "changes to be committed".

My .gitignore file has a line:

/vendor

And I thought that it would prevent any files in "/vendor" folder to be added to index and commited. But it seems to me now that all the changes in this folder are going to be committed to server which I don't want.

Are changes in '/vendor' folder are going to be committed and pushed to remote despite '/vendor' is in .gitignore? If yes, how can I undo git add?:)

Thank you in advance.

I don't think my question is duplicate (I've read them). My .gitignore had /vendor in it before I deleted vendor folder and re-installed everything via composer.

Sergej Fomin
  • 1,822
  • 3
  • 24
  • 42
  • 1
    It is duplicate, but it's still too bad folks around here would rather harp on that than help close the gap in understanding that makes you think not. gitignore DOES NOT IGNORE CHANGES. It ignores untracked files. Paths where files already exist in the repo are completely unaffected by .gitignore, even if they are listed in .gitignore before a subsequent change. There is *no* reliable way to say to git, "this file is part of my commit but I want you to ignore further changes made to this file". You can unstage the changes to vendor with a command like `git reset HEAD -- vendor` – Mark Adelsberger Aug 13 '18 at 15:36
  • @Mark Adelsberger - thank you very much, it works! though I didn't understand what gitignore does exactly. I need to read more:) – Sergej Fomin Aug 13 '18 at 15:58
  • It's a point that confuses a lot of people, so if nothing else probably the naming could be better. But the thing to remember is this: exclusion rules (including .gitignore) do only one thing - they prevent untracked files from accidentally becoming tracked files. – Mark Adelsberger Aug 13 '18 at 16:12
  • @MarkAdelsberger, can ask one more question? I did as you said (unstaged 'vendor' folder) and pushed a commit. When I modified some files in the project and wanted to make another commit git-status showed that all those 'vendor' files are still tracked and i had to manually choose which files to 'git add'. It's quite annoying, because usually i just do 'git add .' and that stages all modified files. Is there a way I can delete those deleted/modified 'vendor' files from the 'Changes not staged for commit' forever? Thank you again! – Sergej Fomin Aug 14 '18 at 07:40
  • When you unstage the changes to files, that means the index entries for those files look the same as the checked out commit - i.e. another commit won't change them. This is different from untracking a file, which means that it doesn't appear in the index, that the next commit won't contain that file, and that when each user first advances their clone to that commit (or later), the file will be deleted from their work tree. If you don't need any copy of the files in the repo, then you can untrack them (`git rm --cached vendor/*`), but you'll need to coordinate with any other users to avoid... – Mark Adelsberger Aug 14 '18 at 12:44
  • ...problems with the files being deleted. A variation (assuming you don't need the files in the repo going forward) is to first modify your build setup such that the files are expected to be outside the work tree, then once people have them moved you can safely remove them from the commit. If you do need the files (or parts of them) in the repo, then the situation is more complex (and the comments format isn't flexible enough to discuss all the options; but generally: use build tooling to separate what should be tracked from what shouldn't, and try to keep the latter out of the work tree.) – Mark Adelsberger Aug 14 '18 at 12:44
  • @MarkAdelsberger, thanx! I have to go now so I'll think about your reply later:) Though I am confused with 'repo' and 'work tree'. I work alone on this project. I understand terms "Working directory" (folder with files on computer), "Index" ("files from WD ready to commit) and Repository (remote where I push the files). I need all vendor files to stay in my WD, I just don't need git to show me that they have been deleted/modified when I did "composer install" several commits ago (beginning of my post). If they''l be deleted/modified in the future - it's ok to track them again. – Sergej Fomin Aug 14 '18 at 13:23

0 Answers0