user6826691
user6826691

Reputation: 2031

Ignore directory

I'm trying to ignore a directory when i do a diff against the master branch

changed=()
while IFS='' read -r line; do changed+=("$line"); done < <(git --no-pager diff --':!modules*' origin/master --name-only | sed 's#\(.*\)/.*#\1#' | uniq)
echo "Files changed: ${changed[*]}"

folder structure: I want to ignore any modules/* directory.

script.sh 
dev-1
  - nonprod 
      - dir1
      - dir2
  - prod
      - testdir1
      - testdir2
dev-2
  - modules
     - content-dir
  - nonprod
     - content-dir
  - prod

Upvotes: 0

Views: 53

Answers (1)

torek
torek

Reputation: 489828

You've gone way overboard writing this bash script, trying to compensate for what's really just a typo:

git --no-pager diff --':!modules*'

This needs to be:

git --no-pager diff -- ':!modules*'

Note the single SPACE between the two dashes and the ':!modules*' pathspec.

(If you want to ignore modules and all its subdirectories, :!modules is sufficient. The * at the end will have Git skip over files or directories named, e.g., modulesfrink and moduleszoidberg as well as modules, so it's probably harmless.)

Separately, the branch argument to git diff, as well as the --name-only part, must come before the --, so you actually need:

git --no-pager diff origin/master --name-only -- ':!modules'

The --, surrounded by spaces on both sides, tells Git: everything after this is a pathspec. While :!modules is a pathspec, origin/master and --name-only are not pathspecs.

Upvotes: 1

Related Questions