Search code examples
gitgit-diff

Creating patch using git diff for uncommitted changes shows a/.... and b/


I am trying to create a patch for uncommitted changes in my workspace using command line . I am using following command to create patch

git diff > diff.patch .

This does create a patch but in the patch it shows diff as this

diff --git a/hedwig-client/src/main/java/org/apache/hedwig/client/netty/impl/multiplex/MultiplexHChannelManager.java b/hedwig-client/src/main/java/org/apache/hedwig/client/netty/impl/multiplex/MultiplexHChannelManager.java
index f28a6b2..3db2b7f 100644
--- a/hedwig-client/src/main/java/org/apache/hedwig/client/netty/impl/multiplex/MultiplexHChannelManager.java
+++ b/hedwig-client/src/main/java/org/apache/hedwig/client/netty/impl/multiplex/MultiplexHChannelManager.java

I want this a and b in the path not to be present . So that it shud look like

diff --git hedwig-client/src/main/java/org/apache/hedwig/client/netty/impl/multiplex/MultiplexHChannelManager.java hedwig-client/src/main/java/org/apache/hedwig/client/netty/impl/multiplex/MultiplexHChannelManager.java

Any idea how to do this .


Solution

  • There's a command line switch for that: git diff --no-prefix, but you don't really want to use git diff, you should do the right thing and make commits on private branches, and then use git format-patch to produce nicely-formatted patch series out of these (it accepts the same switches).

    There's also --src-prefix and --dst-prefix to specify arbitrary paths. But keep in mind that, even when not using git, most people would use patch -sp1 or something similar... a prefix path is almost always expected.