My name’s Anton Eprev and I’m a web developer working as front-end engineer at Booking.com in Amsterdam, Netherlands. I’m on Twitter, GitHub and Unsplash.

Open all modified files in editor

Often I finish working day without committing changes to the repository. Thus, next morning I need to open all the files I was working yesterday. And I found an efficient way to do this.

$ vim -p $(git diff --name-only HEAD | sed "s,$(git rev-parse --show-prefix),," | tr "\n" " ")

It opens Vim and loads all modified files in tabs. You could add this command as an alias to your .bashrc, but adding this to .gitconfig seems like a better option. This is what you need to add to your ~/.gitconfig.

open = "!vim -c \"cd $GIT_PREFIX\" -p $(git diff --name-only HEAD | tr '\\n' ' ')"

To run this command you need to type git open in the terminal. Since all commands prefixed with an exclamation point are executed from the top-level directory of a repository, we need to change working directory in Vim to the current one. And of course you can replace Vim by your favorite editor or event by $EDITOR.

Besides, If you use sort of file watchers to perform certain operations when files change, then you would find the following command quite helpful. It changes modification time of all modified files at once.

touch = "!touch -c $(git diff --name-only HEAD | tr '\\n' ' ')"

You can find more handy aliases in .dotfiles of mine.

If you liked this post and think others should read it, please share it on Twitter.