Search code examples
angularjsgitlaravelgulplaravel-elixir

Git keeps deleting Laravel Elixir (Gulp) generated files


I've been working on a Laravel/AngularJS project in a local branch for a few weeks.

I checked the status before committing, and got these Laravel Elixir generated files:

modified:   public/angular_merge/all.js
modified:   public/angular_merge/all.js.map
renamed:    public/build/angular_merge/all-8b179644.js -> public/build/angular_merge/all-a1f3dc90.js
modified:   public/build/angular_merge/all.js.map
modified:   public/build/rev-manifest.json

I committed my changes, and merged them into master, and it merged with a conflict. I fixed the conflict and ran a git status, and saw this:

deleted:    public/angular_merge/all.js
deleted:    public/build/angular_merge/all-a1f3dc90.js
deleted:    public/build/angular_merge/all.js.map
deleted:    public/build/rev-manifest.json

All these files are created by Elixir.
To fix this, I've tried making a small edit to each file and committing. I've also tried moving to my dev branch, copying the files, and then pasting them in my master branch. This gets the app working again, but when I try to add and commit them:

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

deleted:    angular_merge/all.js
deleted:    angular_merge/all.js.map

Untracked files:
  (use "git add <file>..." to include in what will be committed)

public/angular_merge/all.js
public/build/

The thing is, older versions of these files are already in production, so this has never happened before.

My knowledge of Git is somewhat beginner. I've only been using it for a year, but nothing like this has happened to me before and I'm stumped.


Solution

  • Those file are being generated every time you build/compile your code so they will modified/deleted on every build/compile action

    How to resolve it?

    Using .gitignore

    Add those files to your .gitignore. By doing so they will be "transparent" to git so you will not see them in the git status again.
    But if they are already committed to the repository you will have to remove them from the staging area git rm --cached ..., commit those changes and then you will not see them again.


    --assume-unchanged

    If you want to leave the current files as is without deleting them from the repository you can use the git update-index --assume-unchanged <file>.
    This command will temporarily ignore changes in the given file.