如何合並Git 代碼庫中牛人的代碼到自己的庫


github for Windows使用介紹 這篇文章可以很好帶我們入門github,同時還帶了一個gitshell,這個工具可以運行github的所有命令,命令才能干更多事情,比如今天我們要完成的一個任務就是如何如何合並Git 代碼庫中牛人的代碼到自己的庫。

image

Windows PowerShell
版權所有(C) 2012 Microsoft Corporation。保留所有權利。

C:\Users\geffzhang\Documents\GitHub\SharpOAuth2 [master]> git branch –a    # 查看所有分支
* master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
C:\Users\geffzhang\Documents\GitHub\SharpOAuth2 [master]> git remote add coretea
m git://github.com/ghorsey/SharpOAuth2.git  #加入主項目地址,以便跟上更新
C:\Users\geffzhang\Documents\GitHub\SharpOAuth2 [master]> git fetch coreteam
remote: Counting objects: 297, done.  #獲取主項目更新
remote: Compressing objects: 100% (108/108), done.
remote: Total 227 (delta 147), reused 165 (delta 85)Receiving objects:  73% (166
Receiving objects:  74% (168/227), 60.00 KiB | 10 KiB/s
Receiving objects: 100% (227/227), 74.24 KiB | 10 KiB/s, done.
Resolving deltas: 100% (147/147), completed with 48 local objects.
From git://github.com/ghorsey/SharpOAuth2
* [new branch]      master     -> coreteam/master

#建立主項目作為自己的分支
C:\Users\geffzhang\Documents\GitHub\SharpOAuth2 [master]> git checkout -b coreteam coreteam/master
Branch coreteam set up to track remote branch master from coreteam.
Switched to a new branch 'coreteam'
C:\Users\geffzhang\Documents\GitHub\SharpOAuth2 [coreteam]> git branch -a
* coreteam
  master
  remotes/coreteam/master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

#現在你可以追蹤最新的更新並把它們合並到你自己的分支里

# 切換到master分支
C:\Users\geffzhang\Documents\GitHub\SharpOAuth2 [coreteam]> git checkout master
Switched to branch 'master'

將 coreteam/master 合並到本地的 Master 分支

C:\Users\geffzhang\Documents\GitHub\SharpOAuth2 [master]> git merge coreteam/master
Auto-merging README.md
Merge made by the 'recursive' strategy.
README => README.md                                |  30 +-
.../Provider/Mvc/SharpOAuth2.Provider.Mvc.dll      | Bin 5120 -> 5120 bytes
.../Provider/Mvc/SharpOAuth2.Provider.Mvc.pdb      | Bin 11776 -> 11776 bytes
...h2.Provider.ResourceAuthorizationHttpModule.dll | Bin 8704 -> 8704 bytes
...h2.Provider.ResourceAuthorizationHttpModule.pdb | Bin 17920 -> 17920 bytes
code/deploy/Provider/SharpOAuth2.Framework.dll     | Bin 9216 -> 9216 bytes
code/deploy/Provider/SharpOAuth2.Framework.pdb     | Bin 11776 -> 11776 bytes
.../SharpOAuth2.Provider.Globalization.dll         | Bin 13312 -> 13312 bytes
.../SharpOAuth2.Provider.Globalization.pdb         | Bin 28160 -> 28160 bytes
code/deploy/Provider/SharpOAuth2.Provider.dll      | Bin 36352 -> 37888 bytes
code/deploy/Provider/SharpOAuth2.Provider.pdb      | Bin 130560 -> 136704 bytes

code/src/RESTSample/Properties/AssemblyInfo.cs     |   4 +-
code/src/SharpOAuth2.Client/AccessToken.cs         |   1 +
.../SharpOAuth2.Client/Properties/AssemblyInfo.cs  |   4 +-
.../Properties/AssemblyInfo.cs                     |   4 +-
code/src/SharpOAuth2.Framework/IToken.cs           |   2 +-
.../Properties/AssemblyInfo.cs                     |   4 +-
.../Properties/AssemblyInfo.cs                     |   4 +-
.../src/SharpOAuth2.Mvc/Properties/AssemblyInfo.cs |   4 +-
.../OAuthAuthorizeModule.cs                        |   7 +-
.../Properties/AssemblyInfo.cs                     |   4 +-
.../Properties/AssemblyInfo.cs                     |   4 +-
.../SharpOAuth2.Tests/Properties/AssemblyInfo.cs   |   4 +-
.../AuthorizationProviderTests.cs                  | 364 ++++++++++-----------
.../Processor/ImplicitFlowProcessorTests.cs        |   2 +-
.../ResourceEndpoint/ResourceProviderTests.cs      |   2 +-
.../Processors/AuthenticationCodeProcessorTests.cs |   4 +-
.../AuthorizationEndpoint/AuthorizationContext.cs  |   2 +-
.../AuthorizationEndpoint/IAuthorizationContext.cs |   2 +-
.../Processor/AuthorizationCodeProcessor.cs        |   2 +-
.../Processor/ImplicitFlowProcessor.cs             |   2 +-
code/src/SharpOAuth2/Domain/AccessTokenBase.cs     |  93 +++---
.../SharpOAuth2/Domain/AuthorizationGrantBase.cs   |  24 +-
code/src/SharpOAuth2/Domain/IAuthorizationGrant.cs |  12 +
.../Fluent/FluentAuthorizationContext.cs           | 188 +++++------
code/src/SharpOAuth2/Fluent/FluentTokenContext.cs  | 146 ++++-----
code/src/SharpOAuth2/Framework/ErrorResponse.cs    |  22 ++
code/src/SharpOAuth2/Properties/AssemblyInfo.cs    |   8 +-
.../ResourceEndpoint/Processors/BearerProcessor.cs |   2 +-
.../ResourceEndpoint/ResourceContext.cs            |  52 +++
.../ResourceEndpoint/ResourceProvider.cs           |  73 +++--
.../Services/IAuthorizationGrantService.cs         |  16 +-
code/src/SharpOAuth2/Services/ITokenService.cs     |  22 +-
code/src/SharpOAuth2/SharpOAuth2.Provider.csproj   |   1 +
.../Processor/AuthenticationCodeProcessor.cs       |  44 +--
.../AuthorizationGrant.cs                          |   3 +-
.../Properties/AssemblyInfo.cs                     |   4 +-
.../Service/AuthorizationGrantService.cs           |  96 +++---
.../Service/ClientService.cs                       | 108 +++---
.../Service/TokenService.cs                        | 178 +++++-----
code/src/clean.pyc                                 | Bin 1351 -> 1360 bytes
51 files changed, 838 insertions(+), 710 deletions(-)
rename README => README.md (73%)
create mode 100644 code/src/SharpOAuth2/Domain/IAuthorizationGrant.cs

# 將主分支修改推送到服務器
C:\Users\geffzhang\Documents\GitHub\SharpOAuth2 [master]> git push origin master

Counting objects: 308, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (52/52), done.
Writing objects: 100% (233/233), 75.05 KiB, done.
Total 233 (delta 151), reused 226 (delta 147)
To https://github.com/geffzhang/SharpOAuth2.git
   f3d8955..124c360  master -> master
C:\Users\geffzhang\Documents\GitHub\SharpOAuth2 [master]>

 

下面是一些比較有用的命令的介紹:

# 創建一個版本庫

git init

# 每次修改好了后,可以先將修改存入stage(快照/索引)中

git add <modified files>

# 修改了大量文件則使用下面這個命令批量存入

git add .

# 使用commit將快照/索引中的內容提交到版本庫中

git commit -m"msg"

# 也可以將git add與git commit用一個指令完成

git commit -a-m"msg"

# 將本地的git檔案與github(遠程)上的同步

git push

# 將github(遠程)的git檔案與本地的同步(即更新本地端的repo)

git pull

# 例如,pull指令其實包含了fetch(將變更復制回來)以及merge(合並)操作

git pull git://github.com/tom/test.git

# 另外版本控制系統的branch功能也很有意思,若同時修改bug,又要加入新功能,可以fork出一個branch:一個專門修bug,一個專門加入新功能,等到穩定后再merge合並

git branch bug_fix # 建立branch,名為bug_fix

git checkout bug_fix # 切換到bug_fix

git checkout master #切換到主要的repo

git merge bug_fix #把bug_fix這個branch和現在的branch合並

# 若有remote的branch,想要查看並checkout

git branch -r# 查看遠程branch

git checkout -b bug_fix_local bug_fix_remote #把本地端切換為遠程的bug_fix_remote branch並命名為bug_fix_local

# 還有其它可以查看repo狀態的工具

git log #可以查看每次commit的改變

git diff#可以查看最近一次改變的內容,加上參數可以看其它的改變並互相比較

git show #可以看某次的變更

# 若想知道目前工作樹的狀態,可以輸入

git status

配置http代理
git config --global http.proxy http://web-proxy.xxxxx.com:8080

git 刪除錯誤提交的commit

方法:

    git reset --hard <commit_id>

    git push origin HEAD --force

其他:

    根據–soft –mixed –hard,會對working tree和index和HEAD進行重置:
    git reset –mixed:此為默認方式,不帶任何參數的git reset,即時這種方式,它回退到某個版本,只保留源碼,回退commit和index信息
    git reset –soft:回退到某個版本,只回退了commit的信息,不會恢復到index file一級。如果還要提交,直接commit即可
    git reset –hard:徹底回退到某個版本,本地的源碼也會變為上一個版本的內容


    HEAD 最近一個提交
    HEAD^ 上一次
    <commit_id>  每次commit的SHA1值. 可以用git log 看到,也可以在頁面上commit標簽頁里找到.

git/github初級運用自如

git/github學習筆記

總結自己的Git常用命令

學一點Git--20分鍾git快速上手

如何在github上fork一個項目來貢獻代碼以及同步原作者的修改

Git遠程操作詳解


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM