Skip to content

Instantly share code, notes, and snippets.

@danielbdias
Last active February 12, 2019 21:47
Show Gist options
  • Save danielbdias/82d3e2d4e2165d9026501eae9d903722 to your computer and use it in GitHub Desktop.
Save danielbdias/82d3e2d4e2165d9026501eae9d903722 to your computer and use it in GitHub Desktop.
Listing files that you changed in your current branch
# put here your main branch
MAIN_BRANCH=master
# command to list the files that you changed in your current branch and already commit to that branch
git --no-pager diff --name-only $MAIN_BRANCH
# and command to list the files that you changing right now
git status -s | awk '{if ($1 == "M" || $1 == "??") print $2}'
# execute both commands, concatenate the results and remove the duplicates
( git --no-pager diff --name-only $MAIN_BRANCH; git status -s | awk '{if ($1 == "M" || $1 == "??") print $2}' ) | sort -u
# extra: to pass this files to a command line executable (like RSpec, Reek or Rubocop)
( git --no-pager diff --name-only $MAIN_BRANCH; git status -s | awk '{if ($1 == "M" || $1 == "??") print $2}' ) | sort -u | grep .rb$ | tr '\n' ' ' | xargs bundle exec rubocop
@danielbdias
Copy link
Author

I'm using these commands when I need to test / lint in a large codebase, where the procedures take much time to run.

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