Getting git diff Outputs Without a Prefix

Featured image for sharing metadata for article

Something that has been a pain in my side for quite some time, but I've never thought to find out if there's a fix for, is Git adding a prefix to files when running git diff:

diff --git a/permalinks.yml b/permalinks.yml
index 37cbcd46..2fd826be 100644
--- a/permalinks.yml
+++ b/permalinks.yml
@@ -1,5 +1,6 @@
 ---
 posts:
+- https://www.jvt.me/posts/2019/10/11/git-diff-no-prefix/
 - https://www.jvt.me/posts/2019/10/07/new-team/
 - https://www.jvt.me/posts/2019/10/06/netlify-slow-deploy/
 - https://www.jvt.me/posts/2019/10/05/panic-attacks/

I fairly often work with this output, then copy-paste the filename to then i.e. edit the file. However, as per the above output, the presence of a/ and b/ are always annoying because I have to remove them.

Well, no more, as the following tweet shares:

By running git config --global diff.noprefix true, or adding the below to ~/.gitconfig:

[diff]
	noprefix = true

We now have diffs with the following output:

diff --git permalinks.yml permalinks.yml
index 37cbcd46..2fd826be 100644
--- permalinks.yml
+++ permalinks.yml
@@ -1,5 +1,6 @@
 ---
 posts:
+- https://www.jvt.me/posts/2019/10/11/git-diff-no-prefix/
 - https://www.jvt.me/posts/2019/10/07/new-team/
 - https://www.jvt.me/posts/2019/10/06/netlify-slow-deploy/
 - https://www.jvt.me/posts/2019/10/05/panic-attacks/

Which has no prefix - awesome!

Written by Jamie Tanna's profile image Jamie Tanna on , and last updated on .

Content for this article is shared under the terms of the Creative Commons Attribution Non Commercial Share Alike 4.0 International, and code is shared under the Apache License 2.0.

#blogumentation #git.

This post was filed under articles.

Interactions with this post

Interactions with this post

Below you can find the interactions that this page has had using WebMention.

Have you written a response to this post? Let me know the URL:

Do you not have a website set up with WebMention capabilities? You can use Comment Parade.