Opening changed files in VSCode
A significant portion of my day to day activities are based around code reviews and helping debug issues with other developers. When doing this I will usually open up all of the files that have changed between the current branch and master so that I can get an understanding of the problem as a whole. After a decade of doing this I finally got sick of doing it manually…There must be a better way! I wanted to check out a branch and open all of the changed files in vscode automatically. After a bit of poking around I found the git diff
flag --name-only
which returns the list of changed files. The command ended up like the following:
code -n . `git --no-pager diff --name-only master`
Command breakdown
code -n .
Opens up a new window of vscode with the current project folder open in the ‘explorer’ section.
git --no-pager
disables the pager that git uses by default in zsh (you may not need this flag)
--name-only master
displays a list of files that have changed from master.
Now the next logical step is to make this a bash command and add some customization. Below I’ve defined the command as a function with the ability to define an argument for the branch name and another to filter the list of files. I’ve found the filter to be especially useful when trying to avoid things like test metadata and lock file updates.
# vscodedevsync [branch] [filter regex]
function vscodedevsync() {
code -n . `git --no-pager diff --name-only ${1:-master} | grep -o "$2"`
}
Anyways, hope this helps add a bit of efficiency into your day.