I am trying to create a patch file to be used via reviewboard.
It will be the initial patch.
diff -ruN --exclude=.git empty_dir working_dir > mypatch_00.patch
works but I am getting a "The selected file does not appear to be a diff." error.
Is there any way to get it working using git-diff or diff? Thank you
The git diff command displays the differences between files in two commits or between a commit and your current repository. You can see what text has been added to, removed from, and changed in a file. By default, the git diff command displays any uncommitted changes to your repository.
There is no output to git diff because Git doesn't see any changes inside your repository, only files outside the repository, which it considers 'untracked' and so ignores when generating a diff.
How Do I Find the Difference Between Two Branches? For comparing two branches in Git, you simply run git diff <source-branch-name>.. <destination-branch-name> . Of course, you can replace the current branch name with HEAD.
When viewing a combined diff, if the two files you're comparing have a line that's different from what they were merged into, you will see the ++ to represent: one line that was added does not appear in either file1 or file2.
If you want to get diff for your initial commit (maybe I misunderstood your question), you can display it using
git show COMMIT
Alternatively to get it as file:
git format-patch -1 COMMIT
Where COMMIT
is revision of this commit. If this is your current commit as well, you don't have to specify it at all.
However if your commit is not initial and you want to get full diff for your history, you need to create empty branch first:
git checkout --orphan empty # Create orphaned branch
git read-tree --empty # Remove all files from index
git commit --allow-empty -m 'Empty' # Initial commit
Now you can do full diff against empty branch:
git diff empty..master
If you want the full diff from nothing to a particular commit, there is an easier way than in the accepted answer:
empty_tree=$(git hash-object -t tree /dev/null)
git diff-tree -p ${empty_tree} $MY_COMMIT [${files}...]
The value of ${empty_tree}
is always 4b825dc642cb6eb9a060e54bf8d69288fbee4904
but I prefer not to have the magic number in there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With