Skip to content

Instantly share code, notes, and snippets.

@fredysan
Last active November 6, 2020 16:02
Show Gist options
  • Save fredysan/d84e2122523ad8f80a9656a5dea0c29f to your computer and use it in GitHub Desktop.
Save fredysan/d84e2122523ad8f80a9656a5dea0c29f to your computer and use it in GitHub Desktop.
How to assume unchanged multiple files matching a pattern

Update Git index so that it doesn't show locally modified blocks

git update-index --assume-unchanged $(git status --porcelain | awk '$1 == "M" && $2 ~ "block.block" {print $2}' | tr '\n' ' ')

Explanation:

Update the git index to avoid some files that were modified to appear in the status list.

git update-index --assume-unchanged [file names separated by space]

> git status
        modified:   config/block.block.mycustomblock1.yml
        modified:   config/block.block.mycustomblock2.yml
        modified:   config/something.out.of.scope.yml

> git update-index --assume-unchanged  config/block.block.mycustomblock1.yml config/block.block.mycustomblock2.yml

> git status
        modified:   config/something.out.of.scope.yml

Bash expression that runs a command and puts its output in its place

$(command)

> echo "Today is $(date). A fine day."

Get a simplified list of the changes in the repo.

git status --porcelain

Filter the list to get the items we are interested in.

awk '$1 == "M" && $2 ~ "block.block" {print $2}'

# First column matches "M"
# Second column contains "block.block"
# Print the column 2

Replace new line chatracters with spaces.

tr '/n' ' '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment