skip to Main Content

Many coleagues of mine after composer install they manually edit files and git commit ./vendor alongside with their changes.

In my case I see as a bad practice but makes the app work. Therefore I want to detect what files has changed. The idea is that manual changes are either single-file commits or commits that have number files at ./vendor < total number of files in ./vendor

How I can do this?

2

Answers


  1. Never edit files inside /vendor as it can easily lead to bugs, especially if that dependency is used in other libraries.

    Simple answer – fork that dependency and use your own fork in composer.json.

    Please refer to following answer for full explanation:

    {
        "repositories": [
            {
                "type": "vcs",
                "url": "https://github.com/desyllas/monolog"
            }
        ],
        "require": {
            "monolog/monolog": "dev-fix"
        }
    }
    
    
    Login or Signup to reply.
  2. If you need to deal with repository that contains ./vendor/ changes in it and

    Therefore I want to detect what files has changed.

    Your need is justified IMO.

    Solution 1

    git log --name-status
    

    Gives besides typical info also information about changed files (their paths)

    Solution 2

    If you want to narrow result to only files that are changed inside vendor dir use -- ./vendor as the suffix:

    git log --name-status -- ./vendor
    

    Solution 3

    Similar to the ones above but gives a fancy indicator of number of changes inside the file.

    git log --stat
    

    Solution 4

    this way you’ll get paths to files:

    git log --name-only --oneline
    

    taken from this answer

    you may limit its output:

    git log --name-only --oneline HEAD^..HEAD
    

    to see diffenece between tip of your branch (HEAD) and one commit before it (HEAD^) or just put instead of them commit1sha..commit2sha

    Solution 5

    This command focuses more on paths and their modification status (M = Modified, A = Added, etc) instead of log messages:

    git log --name-status --pretty='' commit1..commit2
    

    If you want to get only paths (without mod status) and optionally remove duplicates see this answer – you may also like other answers in that thread.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search