Skip to content

git diff {filename} local.patch

Robert N edited this page Oct 25, 2015 · 1 revision

Get a patch file for a single file changed in the working directory (i.e. not committed):

Git

$ git diff myChangedFile.as > myChangedFile.patch

LibGit2Sharp

var patch = repo.Diff.Compare<Patch> (new List<string>() { "myChangedFile.as" });

Complete cut/paste example:

using System;
using System.Collections.Generic;
using LibGit2Sharp;

namespace libgitdiff
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			var repo = new Repository ("/your/repo/path");
			foreach (var item in repo.RetrieveStatus()) {
				if (item.State == FileStatus.Modified) {
					var patch = repo.Diff.Compare<Patch> (new List<string>() { item.FilePath });
					Console.WriteLine ("~~~~ Patch file ~~~~");
					Console.WriteLine (patch.Content);
				}
			}
		}
	}
}
Clone this wiki locally
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy