如何使用C#代码获取git代码库的提交计数

roony 2015-07-27 03:35:02
如何使用C#代码获取git代码库的提交计数
如题,多谢~
...全文
513 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
roony 2015-07-29
  • 打赏
  • 举报
回复
引用 11 楼 shingoscar 的回复:
分支名称就是那个HEAD
好的。谢谢。最终这个方法在本地或者iis上是可以的。但是我们这个项目是把app放到azure web app上,所以这个方法肯定是不行了。郁闷。。
Poopaye 2015-07-27
  • 打赏
  • 举报
回复
分支名称就是那个HEAD
roony 2015-07-27
  • 打赏
  • 举报
回复
引用 7 楼 shingoscar 的回复:
		int count = 0;

		void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
		{
			if(e.Data != null)
				++count;
		}

		void Run()
		{
			Process p = new Process();
			p.StartInfo.FileName = @"D:\Program Files (x86)\Git\bin\git.exe";
			p.StartInfo.Arguments = "rev-list HEAD";
			p.StartInfo.WorkingDirectory = @"project-path";
			p.StartInfo.CreateNoWindow = true;
			p.StartInfo.UseShellExecute = false;
			p.StartInfo.RedirectStandardOutput = true;
			p.OutputDataReceived += p_OutputDataReceived;
			count = 0;
			p.Start();
			p.BeginOutputReadLine();
			p.WaitForExit();

			Console.WriteLine(count);
		}
有两处错误,e.Data有可能是空的,不应该记录 另外要指定一下WorkingDirectory,就是你版本库的位置 版本就是你分支的名称
不设置分支名称,默认就能获取到当前分支的信息。
roony 2015-07-27
  • 打赏
  • 举报
回复
引用 7 楼 shingoscar 的回复:
		int count = 0;

		void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
		{
			if(e.Data != null)
				++count;
		}

		void Run()
		{
			Process p = new Process();
			p.StartInfo.FileName = @"D:\Program Files (x86)\Git\bin\git.exe";
			p.StartInfo.Arguments = "rev-list HEAD";
			p.StartInfo.WorkingDirectory = @"project-path";
			p.StartInfo.CreateNoWindow = true;
			p.StartInfo.UseShellExecute = false;
			p.StartInfo.RedirectStandardOutput = true;
			p.OutputDataReceived += p_OutputDataReceived;
			count = 0;
			p.Start();
			p.BeginOutputReadLine();
			p.WaitForExit();

			Console.WriteLine(count);
		}
有两处错误,e.Data有可能是空的,不应该记录 另外要指定一下WorkingDirectory,就是你版本库的位置 版本就是你分支的名称
刚试了一下,版本库的位置,就是本地的路径吧。可以执行了。请问分支名称赋值到哪里?
roony 2015-07-27
  • 打赏
  • 举报
回复
引用 7 楼 shingoscar 的回复:
		int count = 0;

		void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
		{
			if(e.Data != null)
				++count;
		}

		void Run()
		{
			Process p = new Process();
			p.StartInfo.FileName = @"D:\Program Files (x86)\Git\bin\git.exe";
			p.StartInfo.Arguments = "rev-list HEAD";
			p.StartInfo.WorkingDirectory = @"project-path";
			p.StartInfo.CreateNoWindow = true;
			p.StartInfo.UseShellExecute = false;
			p.StartInfo.RedirectStandardOutput = true;
			p.OutputDataReceived += p_OutputDataReceived;
			count = 0;
			p.Start();
			p.BeginOutputReadLine();
			p.WaitForExit();

			Console.WriteLine(count);
		}
有两处错误,e.Data有可能是空的,不应该记录 另外要指定一下WorkingDirectory,就是你版本库的位置 版本就是你分支的名称
请问用git bash 如何查看版本库的位置?git不太熟,多谢了~ 另外,分支名称赋值到哪里?
Poopaye 2015-07-27
  • 打赏
  • 举报
回复
		int count = 0;

		void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
		{
			if(e.Data != null)
				++count;
		}

		void Run()
		{
			Process p = new Process();
			p.StartInfo.FileName = @"D:\Program Files (x86)\Git\bin\git.exe";
			p.StartInfo.Arguments = "rev-list HEAD";
			p.StartInfo.WorkingDirectory = @"project-path";
			p.StartInfo.CreateNoWindow = true;
			p.StartInfo.UseShellExecute = false;
			p.StartInfo.RedirectStandardOutput = true;
			p.OutputDataReceived += p_OutputDataReceived;
			count = 0;
			p.Start();
			p.BeginOutputReadLine();
			p.WaitForExit();

			Console.WriteLine(count);
		}
有两处错误,e.Data有可能是空的,不应该记录 另外要指定一下WorkingDirectory,就是你版本库的位置 版本就是你分支的名称
roony 2015-07-27
  • 打赏
  • 举报
回复
引用 4 楼 shingoscar 的回复:
		int count = 0;

		void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
		{
			++count;
		}

		void Run()
		{
			Process p = new Process();
			p.StartInfo.FileName = @"D:\Program Files (x86)\Git\bin\git.exe";
			p.StartInfo.Arguments = "rev-list HEAD";
			p.StartInfo.CreateNoWindow = true;
			p.StartInfo.UseShellExecute = false;
			p.StartInfo.RedirectStandardOutput = true;
			p.OutputDataReceived += p_OutputDataReceived;
			count = 0;
			p.Start();
			p.BeginOutputReadLine();
			p.WaitForExit();

			Console.WriteLine(count);
		}
您好,多谢你的回复。我试了一下,怎么程序进不到回调函数里呢。另外,路径我知道是什么,版本是什么意思?
Poopaye 2015-07-27
  • 打赏
  • 举报
回复
路径和版本请自行替换
Poopaye 2015-07-27
  • 打赏
  • 举报
回复
		int count = 0;

		void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
		{
			++count;
		}

		void Run()
		{
			Process p = new Process();
			p.StartInfo.FileName = @"D:\Program Files (x86)\Git\bin\git.exe";
			p.StartInfo.Arguments = "rev-list HEAD";
			p.StartInfo.CreateNoWindow = true;
			p.StartInfo.UseShellExecute = false;
			p.StartInfo.RedirectStandardOutput = true;
			p.OutputDataReceived += p_OutputDataReceived;
			count = 0;
			p.Start();
			p.BeginOutputReadLine();
			p.WaitForExit();

			Console.WriteLine(count);
		}
roony 2015-07-27
  • 打赏
  • 举报
回复
引用 2 楼 starfd 的回复:
太高端了,不懂……
哈哈
  • 打赏
  • 举报
回复
太高端了,不懂……
roony 2015-07-27
  • 打赏
  • 举报
回复
或者怎么用c# 执行git bash命令 并获取返回值

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧