程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> git for c#, commit本地,push服務器

git for c#, commit本地,push服務器

編輯:C#入門知識

//ok
        private static void push()
        {
            string wkDir = @"E:\DotNet2010\單位工程\Git.Client\lib2Test\ConsoleApplication1\bin\Debug\D2Git\.git";
            using (var repo = new Repository(wkDir))
            {

                //此時必須保證存在 one.txt,two.txt 兩個文件
                string fname = "one.txt";
                repo.Index.Stage(fname);
                repo.Commit("add one", Constants.Signature, Constants.Signature);


                fname = "two.txt";
                repo.Index.Stage(fname);
                repo.Commit("add two", Constants.Signature, Constants.Signature);

                var nk = repo.Network;
                PushOptions po = new PushOptions
                {
                    CredentialsProvider = (x, y, z) => new UsernamePasswordCredentials { Username = "admin", Password = "admin" }
                };
                nk.Push(repo.Head, po);
                nk.Push(repo.Branches["master"], po);

            }
        }


    public static class Constants
    {
        public static readonly Signature Signature = new Signature("javasuki", "[email protected]", new DateTimeOffset(2014, 06, 22, 10, 58, 27, TimeSpan.FromHours(2)));
    }


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved