欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

GitHub具體教程

系統(tǒng) 1789 0

GitHub具體教程


1 ?Git具體教程


1.1 ?Git簡單介紹


1.1.1 ?Git是何方神圣?


Git是用C語言開發(fā)的分布版本號控制系統(tǒng)。版本號控制系統(tǒng)能夠保留一個文件集合的歷史記錄,并能回滾文件集合到還有一個狀態(tài)(歷史記錄狀態(tài))。還有一個狀態(tài)能夠是不同的文件,也能夠是不同的文件內(nèi)容。舉個樣例,你能夠?qū)⑽募限D(zhuǎn)換到兩天之前的狀態(tài),或者你能夠在生產(chǎn)代碼和實驗性質(zhì)的代碼之間進行切換。文件集合往往被稱作是“源碼”。在一個分布版本號控制系統(tǒng)中,每一個人都有一份完整的源碼(包含源碼全部的歷史記錄信息),并且能夠?qū)@個本地的數(shù)據(jù)進行操作。分布版本號控制系統(tǒng)不須要一個集中式的代碼倉庫。


當(dāng)你對本地的源碼進行了改動,你能夠標(biāo)注他們跟下一個版本號相關(guān)(將他們加到index中),然后提交到倉庫中來(commit)。Git保存了全部的版本號信息,所以你能夠轉(zhuǎn)換你的源碼到不論什么的歷史版本號。你能夠?qū)Ρ镜氐膫}庫進行代碼的提交,然后與其它的倉庫進行同步。你能夠使用Git來進行倉庫的克隆(clone)操作,完整的復(fù)制一個已有的倉庫。倉庫的全部者能夠通過push操作(推送變更到別處的倉庫)或者Pull操作(從別處的倉庫拉取變更)來同步變更。


Git支持分支功能(branch)。假設(shè)你想開發(fā)一個新的產(chǎn)品功能,你能夠建立一個分支,對這個分支的進行改動,而不至于會影響到主支上的代碼。


Git提供了命令行工具;這個教程會使用命令行。你也能夠找到圖形工具,譬如與Eclipse配套的EGit工具,可是這些都不會在這個教程中進行描寫敘述。


1.1.2 ?重要的術(shù)語


Git 術(shù)語

術(shù)語 定義
倉庫 一個倉庫包含了全部的版本號信息、全部的分支和標(biāo)記信息.
Repository 在Git中倉庫的每份拷貝都是完整的。倉庫讓你能夠從中
? 取得你的工作副本。
? 一個分支意味著一個獨立的、擁有自己歷史信息的代碼線
分支 (code line)。你能夠從已有的代碼中生成一個新的分支
Branches ,這個分支與剩余的分支全然獨立。默認(rèn)的分支往往是叫
? master。用戶能夠選擇一個分支,選擇一個分支叫做
? checkout.
標(biāo)記 一個標(biāo)記指的是某個分支某個特定時間點的狀態(tài)。通過標(biāo)
Tags 記,能夠非常方便的切換到標(biāo)記時的狀態(tài),比如2009年1月25
? 號在testing分支上的代碼狀態(tài)
提交 提交代碼后,倉庫會創(chuàng)建一個新的版本號。這個版本號能夠在
Commit 興許被又一次獲得。每次提交都包含作者和提交者,作者和
? 提交者能夠是不同的人
URL URl用來標(biāo)識一個倉庫的位置
? 用來表示代碼的一個版本號狀態(tài)。Git通過用SHA1 hash算法
修訂 表示的id來標(biāo)識不同的版本號。每個 SHA1 id都是160位長
Revision ,16進制標(biāo)識的字符串.最新的版本號能夠通過HEAD來獲取.
? 之前的版本號能夠通過"HEAD~1"來獲取,以此類推。


1.1.3 ?索引


Git 須要將代碼的變化顯示的與下一次提交進行關(guān)聯(lián)。舉個樣例,假設(shè)你對一個文件繼續(xù)了改動,然后想將這些改動提交到下一次提交中,你必須將這個文件提交到索引中,通過git add file命令。這樣索引能夠保存全部變化的快照。


新增的文件總是要顯示的加入到索引中來。對于那些之前已經(jīng)提交過的文件,能夠在commit命令中使用-a 選項達到提交到索引的目的。


1.2 ?Git安裝


在Ubuntu上,你能夠通過apt來安裝git命令行工具


            sudo apt-get install git-core

          


對于其它的Linux版本號,請查看相關(guān)的軟件包安裝工具用法。msysgit項目提供了Windows版本號的Git,地址是 http://code.google.com/p/msysgit/


1.3 ?Git配置


你能夠在.gitconfig文件里防止git的全局配置。文件位于用戶的home文件夾。上述已經(jīng)提到每次提交都會保存作者和提交者的信息,這些信息都能夠保存在全局配置中。興許將會介紹配置用戶信息、高亮顯示和忽略特定的文件。


1.3.1 ?用戶信息


通過例如以下命令來配置username和Email

              git config --global user.name "Example Surname"

git config --global user.email "your.email@gmail.com"
# Set default so that all changes are always pushed to the repository
git config --global push.default "matching"

            


獲取Git配置信息,運行下面命令:

              git config --list

            


1.3.2 ?高亮顯示

下面命令會為終端配置高亮

              git config --global color.status auto
git config --global color.branch auto

            


1.3.3 ?忽略特定的文件

能夠配置Git忽略特定的文件或者是目錄。這些配置都放在.gitignore文件里。這個文件能夠存在于不同的目錄中,能夠包括不同的文件匹配模式。為了讓Git忽略bin目錄,在主目錄下放置.gitignore文件,當(dāng)中內(nèi)容為bin。

同一時候Git也提供了全局的配置,core.excludesfile。


1.3.4 ?使用.gitkeep來追蹤空的目錄

Git會忽略空的目錄。假設(shè)你想版本號控制包含空目錄,依據(jù)慣例會在空目錄下放置.gitkeep文件。事實上對文件名稱沒有特定的要求。一旦一個空目錄下有文件后,這個目錄就會在版本號控制范圍內(nèi)。


1.4 ?開始操作Git

興許將通過一個典型的Git工作流來學(xué)習(xí)。在這個過程中,你會創(chuàng)建一些文件、創(chuàng)建一個本地的Git倉庫、提交你的文件到這個倉庫中。這之后,你會克隆一個倉庫、在倉庫之間通過pull和push操作來交換代碼的改動。凝視(以#開頭)解釋了命令的詳細含義,讓我們打開命令行開始操作吧。


1.4.1 ?創(chuàng)建內(nèi)容

以下創(chuàng)建一些文件,它們會被放到版本號控制之中

              
                #
              
              
                Switch to home

              
              
                cd
              
               ~/

              
                # 
              
              
                Create a directory

              
              mkdir ~/repo01

              
                # 
              
              
                Switch into it

              
              
                cd
              
               repo01

              
                # 
              
              
                Create a new directory

              
              mkdir datafiles

              
                # 
              
              
                Create a few files

              
              touch test01
touch test02
touch test03
touch datafiles/data.txt

              
                # 
              
              
                Put a little text into the first file

              
              ls >test01

            


1.4.2 ?創(chuàng)建倉庫、加入文件和提交更改

每一個Git倉庫都是放置在.git文件夾下.這個文件夾包括了倉庫的全部歷史記錄,.git/config文件包括了倉庫的本地配置。

下面將會創(chuàng)建一個Git倉庫,加入文件倒倉庫的索引中,提交更改。

              
                # 
              
              
                Initialize the local Git repository

              
              git init

              
                # 
              
              
                Add all (files and directories) to the Git repository

              
              git add .

              
                # 
              
              
                Make a commit of your file to the local repository

              
              git commit -m 
              
                "Initial commit"
              
              
                # 
              
              
                Show the log file

              
              git log

            


1.4.3 ?diff命令與commit更改

通過git diff命令,用戶能夠查看更改。通過改變一個文件的內(nèi)容,看看gitdiff命令輸出什么,然后提交這個更改到倉庫中

              
                # 
              
              
                Make some changes to the file

              
              
                echo
              
              
                "This is a change"
              
               > test01

              
                echo
              
              
                "and this is another change"
              
               > test02


              
                # 
              
              
                Check the changes via the diff command 

              
              git diff


              
                # 
              
              
                Commit the changes, -a will commit changes for modified files

              
              
                # 
              
              
                but will not add automatically new files

              
              git commit -a -m 
              
                "These are new changes"
              
            


1.4.4 ?Status, Diff 和 Commit Log

以下會向你展示倉庫現(xiàn)有的狀態(tài)以及過往的提交歷史

              
                # 
              
              
                Make some changes in the file

              
              
                echo
              
              
                "This is a new change"
              
               > test01

              
                echo
              
              
                "and this is another new change"
              
               > test02


              
                # 
              
              
                See the current status of your repository 

              
              
                # 
              
              
                (which files are changed / new / deleted)

              
              git status

              
                # 
              
              
                Show the differences between the uncommitted files 

              
              
                # 
              
              
                and the last commit in the current branch

              
              git diff


              
                # 
              
              
                Add the changes to the index and commit

              
              git add . && git commit -m 
              
                "More chaanges - typo in the commit message"
              
              
                # 
              
              
                Show the history of commits in the current branch

              
              git log

              
                # 
              
              
                This starts a nice graphical view of the changes

              
              gitk --all

            


1.4.5 ?更正提交的信息 - git amend

通過git amend命令,我們能夠改動最后提交的的信息。上述的提交信息中存在錯誤,以下會改動這個錯誤。

              git commit --amend -m "More changes - now correct"

            


1.4.6 ?刪除文件

假設(shè)你刪除了一個在版本號控制之下的文件,那么使用git add .不會在索引中刪除這個文件。須要通過帶-a選項的git commit命令和-A選項的git add命令來完畢

              
                # 
              
              
                Create a file and put it under version control

              
              touch nonsense.txt
git add . && git commit -m 
              
                "a new file has been created"
              
              
                # 
              
              
                Remove the file

              
              rm nonsense.txt

              
                # 
              
              
                Try standard way of committing -> will not work 

              
              git add . && git commit -m 
              
                "a new file has been created"
              
              
                # 
              
              
                Now commit with the -a flag

              
              git commit -a -m 
              
                "File nonsense.txt is now removed"
              
              
                # 
              
              
                Alternatively you could add deleted files to the staging index via

              
              git add -A . 
git commit -m 
              
                "File nonsense.txt is now removed"
              
            


1.5 ?遠端倉庫(remote repositories)


1.5.1 ?設(shè)置一個遠端的Git倉庫


我們將創(chuàng)建一個遠端的Git倉庫。這個倉庫能夠存儲在本地或者是網(wǎng)絡(luò)上。


遠端Git倉庫和標(biāo)準(zhǔn)的Git倉庫有例如以下區(qū)別:一個標(biāo)準(zhǔn)的Git倉庫包含了源碼和歷史信息記錄。我們能夠直接在這個基礎(chǔ)上改動代碼,由于它已經(jīng)包含了一個工作副本。可是遠端倉庫沒有包含工作副本,僅僅包含了歷史信息。能夠使用–bare選項來創(chuàng)建一個這種倉庫。


為了方便起見,演示樣例中的倉庫創(chuàng)建在本地文件系統(tǒng)上

              
                # 
              
              
                Switch to the first repository

              
              
                cd
              
               ~/repo01

              
                # 
              
              
              
              git clone --bare . ../remote-repository.git


              
                # 
              
              
                Check the content, it is identical to the .git directory in repo01

              
              ls ~/remote-repository.git

            


1.5.2 ?推送更改到其它的倉庫


做一些更改,然后將這些更改從你的第一個倉庫推送到一個遠端倉庫?


cd ~/repo01

echo "Hello, hello. Turn your radio on" > test01echo "Bye, bye. Turn your radio off" > test02

git commit -a -m "Some changes"

git push ../remote-repository.git


1.5.3 ?加入遠端倉庫


除了通過完整的URL來訪問Git倉庫外,還能夠通過git remote add命令為倉庫加入一個短名稱。當(dāng)你克隆了一個倉庫以后,origin表示所克隆的原始倉庫。即使我們從零開始,這個名稱也存在。


              
                # 
              
              
                Add ../remote-repository.git with the name origin

              
              git remote add origin ../remote-repository.git 


              
                # 
              
              
                Again some changes

              
              
                echo
              
              
                "I added a remote repo"
              
               > test02

              
                # 
              
              
                Commit

              
              git commit -a -m 
              
                "This is a test for the new remote origin"
              
              
                # 
              
              
                If you do not label a repository it will push to origin

              
              git push origin

            


1.5.4 ?顯示已有的遠端倉庫


通過下面命令查看已經(jīng)存在的遠端倉庫

              # Show the existing defined remote repositories
git remote

            


1.5.5 ?克隆倉庫

通過下面命令在新的文件夾下創(chuàng)建一個新的倉庫

              
                # 
              
              
                Switch to home

              
              
                cd
              
               ~

              
                # 
              
              
                Make new directory

              
              mkdir repo02


              
                # 
              
              
                Switch to new directory

              
              
                cd
              
               ~/repo02

              
                # 
              
              
                Clone

              
              git clone ../remote-repository.git .

            


1.5.6 ?拉取(Pull)更改

通過拉取,能夠從其它的倉庫中獲取最新的更改。在第二個倉庫中,做一些更改,然后將更改推送到遠端的倉庫中。然后第一個倉庫拉取這些更改

              
                # 
              
              
                Switch to home

              
              
                cd
              
               ~


              
                # 
              
              
                Switch to second directory

              
              
                cd
              
               ~/repo02

              
                # 
              
              
                Make changes

              
              
                echo
              
              
                "A change"
              
               > test01

              
                # 
              
              
                Commit

              
              git commit -a -m 
              
                "A change"
              
              
                # 
              
              
                Push changes to remote repository

              
              
                # 
              
              
                Origin is automatically maintained as we cloned from this repository

              
              git push origin

              
                # 
              
              
                Switch to the first repository and pull in the changes

              
              
                cd
              
               ~/repo01
git pull ../remote-repository.git/

              
                # 
              
              
                Check the changes

              
              less test01

            


1.5.7 ?還原更改

假設(shè)在你的工作副本中,你創(chuàng)建了不想被提交的文件,你能夠丟棄它。

              # Create a new file with content
touch test04
echo "this is trash" > test04

# Make a dry-run to see what would happen
# -n is the same as --dry-run 
git clean -n

# Now delete
git clean -f

你能夠提取老版本號的代碼,通過提交的ID。git log命令能夠查看提交ID 

# Switch to home
cd ~/repo01
# Get the log
git log

# Copy one of the older commits and checkout the older revision via  譯者注:checkout 后加commit id就是把commit的內(nèi)容拷貝到index和工作副本中 
git checkout commit_name

            


假設(shè)你還未把更改增加到索引中,你也能夠直接還原全部的更改

              
                #
              
              
                Some nonsense change

              
              
                echo
              
              
                "nonsense change"
              
               > test01

              
                # 
              
              
                Not added to the staging index. Therefore we can 

              
              
                # 
              
              
                just checkout the old version

              
              
                #
              
              
                譯者注:checkout后假設(shè)沒有commit id號,就是從index中拷貝數(shù)據(jù)到工作副本,不涉及commit部分的改變

              
              git checkout test01

              
                # 
              
              
                Check the result

              
              cat test01

              
                # 
              
              
                Another nonsense change

              
              
                echo
              
              
                "another nonsense change"
              
               > test01

              
                # 
              
              
                We add the file to the staging index

              
              git add test01

              
                # 
              
              
                Restore the file in the staging index

              
              
                #
              
              
                譯者注:復(fù)制HEAD所指commit的test01文件到index中

              
              git reset HEAD test01

              
                # 
              
              
                Get the old version from the staging index

              
              
                #
              
              
                譯者注:復(fù)制index中test01到工作副本中

              
              git checkout test01

              
                #
              
              
                譯者注,以上兩條命令能夠合并為git checkout HEAD test01

              
              
也能夠通過revert命令進行還原操作 


              
                # 
              
              
                Revert a commit

              
              git revert commit_name

            


即使你刪除了一個未加入到索引和提交的文件,你也能夠還原出這個文件

              
                # 
              
              
                Delete a file

              
              rm test01

              
                # 
              
              
                Revert the deletion

              
              git checkout test01

            


假設(shè)你已經(jīng)加入一個文件到索引中,可是未提交。能夠通過git resetfile 命令將這個文件從索引中刪除

              // Create a file
touch incorrect.txt
// Accidently add it to the index
git add .
// Remove it from the index
git reset incorrect.txt
// Delete the file
rm incorrect.txt

            


假設(shè)你刪除了目錄且尚未提交,能夠通過下面命令來恢復(fù)這個目錄 。譯者注:即使已經(jīng)提交,也能夠還原

              git checkout HEAD -- your_dir_to_restore

            


譯者注:checkout和reset這兩個命令的含義是不同的,能夠參閱這篇文章 http://marklodato.github.com/visual-git-guide/index-en.html


1.5.8 ?標(biāo)記

Git能夠使用對歷史記錄中的任一版本號進行標(biāo)記。這樣在興許的版本號中就能輕松的找到。一般來說,被用來標(biāo)記某個發(fā)行的版本號。能夠通過git tag命令列出全部的標(biāo)記,通過例如以下命令來創(chuàng)建一個標(biāo)記和恢復(fù)到一個標(biāo)記

              git tag version1.6 -m 'version 1.6'      
git checkout <tag_name>

            


1.6 ?分支、合并


1.6.1 ?分支


通過分支,能夠創(chuàng)造獨立的代碼副本。默認(rèn)的分支叫master。Git消耗非常少的資源就能創(chuàng)建分支。Git鼓舞開發(fā)者多使用分支


以下的命令列出了全部的本地分支,當(dāng)前所在的分支前帶有*號

              git branch 

            


假設(shè)你還想看到遠端倉庫的分支,能夠使用以下的命令

              git branch -a

            


能夠通過以下的命令來創(chuàng)建一個新的分支

              # Syntax: git branch <name> <hash>
# <hash> in the above is optional 
# if not specified the last commit will be used
# If specified the corresponding commit will be used
git branch testing
# Switch to your new branch
git checkout testing
# Some changes
echo "Cool new feature in this branch" > test01
git commit -a -m "new feature"
# Switch to the master branch
git checkout master
# Check that the content of test01 is the old one
cat test01

            


1.6.2 ?合并


通過Merge我們能夠合并兩個不同分支的結(jié)果。Merge通過所謂的三路合并來完畢。分別來自兩個分支的最新commit和兩個分支的最新公共commit.能夠通過例如以下的命令進行合并

              # Syntax: git merge <branch-name>
git merge testing

            


一旦合并發(fā)生了沖突,Git會標(biāo)志出來,開發(fā)者須要手工的去解決這些沖突。解決沖突以后,就能夠?qū)⑽募尤氲剿饕校缓筇峤桓?


1.6.3 ?刪除分支


刪除分支的命令例如以下:

              #Delete branch testing
git branch -d testing
# Check if branch has been deleted
git branch

            


1.6.4 ?推送(push)一個分支到遠端倉庫


默認(rèn)的,Git僅僅會推送匹配的分支的遠端倉庫。這意味在使用git push命令默認(rèn)推送你的分支之前,須要手工的推送一次這個分支。

              # Push testing branch to remote repository
git push origin testing

# Switch to the testing branch
git checkout testing

# Some changes
echo "News for you" > test01
git commit -a -m "new feature in branch"

# Push all including branch
git push

            

通過這樣的方式,你能夠確定哪些分支對于其它倉庫是可見的,而哪些僅僅是本地的分支


1.7 ?解決合并沖突


假設(shè)兩個不同的開發(fā)者對同一個文件進行了改動,那么合并沖突就會發(fā)生。而Git沒有智能到自己主動解決合并兩個改動。


在這一節(jié)中,我們會首先制造一個合并沖突,然后解決它,并應(yīng)用到Git倉庫中。


以下會產(chǎn)生一個合并沖突


            # Switch to the first directory
cd ~/repo01
# Make changes
touch mergeconflict.txt
echo "Change in the first repository" > mergeconflict.txt
# Stage and commit
git add . && git commit -a -m "Will create merge conflict 1"

# Switch to the second directory
cd ~/repo02
# Make changes
touch mergeconflict.txt
echo "Change in the second repository" > mergeconflict.txt
# Stage and commit
git add . && git commit -a -m "Will create merge conflict 2"
# Push to the master repository
git push

# Now try to push from the first directory
# Switch to the first directory
cd ~/repo01
# Try to push --> you will get an error message
git push
# Get the changes
git pull origin master

          


Git將沖突放在收到影響的文件里,文件內(nèi)容例如以下:

            <<<<<<< HEAD
Change in the first repository
=======
Change in the second repository
>>>>>>> b29196692f5ebfd10d8a9ca1911c8b08127c85f8

          


上面部分是你的本地倉庫,以下部分是遠端倉庫。如今編輯這個文件,然后commit更改。另外的,你能夠使用git mergetool命令

            # Either edit the file manually or use 
git mergetool
# You will be prompted to select which merge tool you want to use
# For example on Ubuntu you can use the tool "meld"
# After  merging the changes manually, commit them
git commit -m "merged changes"

          


1.8 ?變基(Rebase)


1.8.1 ?在同一分支中應(yīng)用Rebase Commit


通過rebase命令能夠合并多個commit為一個。這樣用戶push更改到遠端倉庫的時候就能夠先改動commit歷史


接下來我們將創(chuàng)建多個commit,然后再將它們rebase成一個commit


              # Create a new file
touch rebase.txt

# Add it to git
git add . && git commit -m "rebase.txt added to index"

# Do some silly changes and commit
echo "content" >> rebase.txt
git add . && git commit -m "added content"
echo " more content" >> rebase.txt
git add . && git commit -m "added more content"
echo " more content" >> rebase.txt
git add . && git commit -m "added more content"
echo " more content" >> rebase.txt
git add . && git commit -m "added more content"
echo " more content" >> rebase.txt
git add . && git commit -m "added more content"
echo " more content" >> rebase.txt
git add . && git commit -m "added more content"

# Check the git log message
git log

            

我們合并最后的七個commit。你能夠通過例如以下的命令交互的完畢

              git rebase -i HEAD~7

            

這個命令會打開編輯器讓你改動commit的信息或者 squash/ fixup最后一個信息.Squash會合并commit信息而fixup會忽略commit信息(待理解)

1.8.2 ?Rebasing多個分支

你也能夠?qū)蓚€分支進行rebase操作。例如以下所述,merge命令合并兩個分支的更改。rebase命令為一個分支的更改生成一個補丁,然后應(yīng)用這個補丁到還有一分支中

使用merge和rebase,最后的源碼是一樣的,可是使用rebase產(chǎn)生的commit歷史更加的少,并且歷史記錄看上去更加的線性

              # Create new branch 
git branch testing
# Checkout the branch
git checkout testing
# Make some changes
echo "This will be rebased to master" > test01
# Commit into testing branch
git commit -a -m "New feature in branch"
# Rebase the master
git rebase master

            


1.8.3 ?Rebase最佳實踐

在push更改到其它的Git倉庫之前,我們須要細致檢查本地分支的commit歷史


在Git中,你能夠使用本地的commit。開發(fā)者能夠利用這個功能方便的回滾本地的開發(fā)歷史。可是在push之前,須要觀察你的本地分支歷史,是否當(dāng)中有些commit歷史對其它用戶來說是無關(guān)的


假設(shè)全部的commit歷史都跟同一個功能有關(guān),非常多情況下,你須要rebase這些commit歷史為一個commit歷史。


交互性的rebase主要就是做重寫commit歷史的任務(wù)。這樣做是安全的,由于commit還沒有被push到其他的倉庫。這意味著commit歷史僅僅有在被push之前被改動。


假設(shè)你改動然后push了一個已經(jīng)在目標(biāo)倉庫中存在的commit歷史,這看起來就像是你實現(xiàn)了一些別人已經(jīng)實現(xiàn)的功能


1.8.4 ?創(chuàng)建和應(yīng)用補丁


一個補丁指的是一個包括對源碼進行改動的文本文件。你能夠?qū)⑦@個文件發(fā)送給某人,然后他就能夠應(yīng)用這個補丁到他的本地倉庫。


以下會創(chuàng)建一個分支,對這個分支所一些改動,然后創(chuàng)建一個補丁,并應(yīng)用這個補丁到master分支


              # Create a new branch
git branch mybranch
# Use this new branch
git checkout mybranch
# Make some changes
touch test05
# Change some content in an existing file
echo "New content for test01" >test01
# Commit this to the branch
git add .
git commit -a -m "First commit in the branch"

# Create a patch --> git format-patch master
git format-patch origin/master
# This created patch 0001-First-commit-in-the-branch.patch

# Switch to the master
git checkout master

# Apply the patch
git apply 0001-First-commit-in-the-branch.patch
# Do your normal commit in the master 
git add .
git commit -a -m "Applied patch"

# Delete the patch 
rm 0001-First-commit-in-the-branch.patch


            


1.9 ?定義同名命令


Git同意你設(shè)定你自己的Git命令。你能夠給你自己經(jīng)常使用的命令起一個縮寫命令,或者合并幾條命令道一個命令上來。


以下的樣例中,定義了git add-commit 命令,這個命令合并了git add . -A 和git commit -m 命令。定義這個命令后,就能夠使用git add-commit -m"message" 了.


            git config --global alias.add-commit '!git add . -A && git commit'

          

可是很不幸,截止寫這篇文章之前,定義同名命令在msysGit中還沒有支持。同名命令不能以!開始。


1.10 ?放棄跟蹤文件


有時候,你不希望某些文件或者目錄被包括在Git倉庫中。可是假設(shè)你把它們加到.gitignore文件里以后,Git會停止跟蹤這個文件。可是它不會將這個文件從倉庫中刪除。這導(dǎo)致了文件或者目錄的最后一個版本號還是存在于倉庫中。為了取消跟蹤這些文件或者目錄,你能夠使用例如以下的命令


            # Remove directory .metadata from git repo
git rm -r --cached .metadata
# Remove file test.txt from repo
git rm --cached test.txt

          

這樣做不會將這些文件從commit歷史中去掉。假設(shè)你想將這些文件從commit歷史中去掉,能夠參考git filter-branch命令


1.11 ?其它實用的命令


以下列出了在日常工作中很實用的Git命令


實用的Git命令


命令 描寫敘述
git blame filename 誰創(chuàng)建了或者是改動了這個文件
git checkout -b mybranch 以上上個commit信息為起點,創(chuàng)建一條
master~1 新的分支


1.12 ?安裝Git服務(wù)


如上所述,我們的操作不須要Git服務(wù)。我能夠僅僅使用文件系統(tǒng)或者是Git倉庫的提供者,像Github或Bitbucket。可是,有時候,擁有一個自己的服務(wù)是比較方便的,在ubuntu下安裝一個服務(wù)相對來說是比較easy的


確定你已經(jīng)安裝了ssh

            apt-get install ssh

          


假設(shè)你還沒有安裝Git服務(wù),安裝它

            sudo apt-get install git-core

          


加入一個名為git的用戶

            sudo adduser git

          


然后使用git用戶進行登陸,創(chuàng)建一個空的倉庫

            # Login to server
# to test use localhost
ssh git@IP_ADDRESS_OF_SERVER

# Create repository
git init --bare example.git

          


如今你就能夠向遠端的倉庫提交變更了

            mkdir gitexample
cd gitexample
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin git@IP_ADDRESS_OF_SERVER:example.git
git push origin master

          


1.13 ?在線的遠端倉庫


1.13.1 ?克隆遠端倉庫


Git支持遠端的操作。Git支持多種的傳輸類型,Git自帶的協(xié)議就叫做git。以下的的命令通過git協(xié)議從克隆一個倉庫

              git clone git@github.com:vogella/gitbook.git

            


相同的,你能夠通過http協(xié)議來克隆倉庫

              # The following will clone via HTTP 
git clone http://vogella@github.com/vogella/gitbook.git

            


1.13.2 ?加入遠端倉庫

假設(shè)你克隆了一個遠端倉庫,那么原先的倉庫就叫做origin

你能夠push改動到origin中,通過 git push origin 命令. 當(dāng)然,push到一個遠端的倉庫須要對倉庫的寫權(quán)限

你能夠通過git remote add name gitrepo 命令加入多個倉庫。比如,你能夠通過http協(xié)議再次加入之前clone過來的倉庫:

              // Add the https protocol 
git remote add githttp https://vogella@github.com/vogella/gitbook.git

            


1.13.3 ?通過http和代理server進行遠端操作

假設(shè)你的防火墻屏蔽了出http以外的全部協(xié)議,那么使用http協(xié)議來獲取倉庫是很好的方法。.

Git相同支持通過代理server使用http協(xié)議。以下的Git命令會展示這一點。你能夠為全部的程序設(shè)置代理server或者僅僅是為Git服務(wù)提供。

以下的樣例用到了環(huán)境變量

              # Linux
export http_proxy=http://proxy:8080
# On Windows
# Set http_proxy=http://proxy:8080 
git clone http://dev.eclipse.org/git/org.eclipse.jface/org.eclipse.jface.snippets.git
# Push back to the origin using http
git push origin

            


以下的樣例僅僅是用到了Git的配置

              // Set proxy for git globally
 git config --global http.proxy http://proxy:8080
// To check the proxy settings
git config --get http.proxy
// Just in case you need to you can also revoke the proxy settings
git config --global --unset http.proxy

            


1.14 ?Git服務(wù)提供商

除了如果自己的服務(wù),你也能夠使用Git服務(wù)提供商提供的服務(wù)。最流行的Git服務(wù)提供站點是GitHub和Bitbucket。它們都提供了有限制的免費服務(wù)


1.14.1 ?GitHub

能夠通過? https://github.com/ ?訪問GitHub. GitHub上全部的公開倉庫都是免費的。假設(shè)你想在上面使用私有的倉庫,那么就須要付費給GitHub


GitHub須要你創(chuàng)建ssh的公鑰私鑰。生成一份Ubuntu的公鑰私鑰能夠訪問 sshkey creation in Ubuntu ,Windows環(huán)境能夠訪問msysgit ssh key generation.


在GitHub上創(chuàng)建一個賬戶和一個倉庫以后。你會收到怎樣將你的項目上傳到GitHUb的指南,當(dāng)中的命令大致例如以下:


              Global setup:
 Set up git
  git config --global user.name "Your Name"
  git config --global user.email your.email@gmail.com
      
Next steps:
  mkdir gitbook 
  cd gitbook
  git init
  touch README
  git add README
  git commit -m 'first commit'
  git remote add origin git@github.com:vogella/gitbook.git
  git push -u origin master
      
Existing Git Repo?
  cd existing_git_repo
  git remote add origin git@github.com:vogella/gitbook.git
  git push -u origin master

            


1.14.2 ?Bitbucket


能夠通過? https://bitbucket.org/ ?訪問Bitbucket. Bitbucket 提供了無限制了公共倉庫和僅僅能有五個人訪問的私有倉庫。假設(shè)你須要超過五個人訪問私有倉庫,就須要付費給Bitbucket


1.15 ?Git的圖形接口


這個教程主要說明Git命令行的使用。完畢了這個教程以后,你可能想要找到一個Git的圖形工具


Git提供了兩個圖形工具。 gitk可以展示倉庫的歷史信息、git gui 讓你可以通過編輯器來完畢Git操作


Eclipse EGit 項目提供了Git與Eclipse的集成,在最新的Eclipse版本號中能夠找到


1.16 ?Kindle版本號教程


這個教程提供了Kindle版本號

Kindle Edition


1.17 ?問題與討論


在提出問題之前,請先查看 vogella FAQ. 假設(shè)你有不論什么的問題或者是從文章中找到錯誤,那么能夠使用www.vogella.com Google Group. 我自己寫了一個簡短的列表 how to create good questions 可能會對你實用.


1.18 ?鏈接和文章

Git homepage

EGit - Teamprovider for Eclipse

Video with Linus Torwalds on Git

Progit book - Free Git book

Video casts about Git

http://code.google.com/p/msysgit/ ?Git on Windows

http://github.com/guides/git-cheat-sheet ?Git Cheat Sheets




Author: hic <lishuo.os.ds@gmail.com>

Date: 2012-08-26 日

HTML generated by org-mode 6.33x in emacs 23

GitHub具體教程


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 亚洲激情视频 | 国产人妻人伦精品潘金莲 | 日本黄色中文字幕 | 精品久久网 | 达达兔午夜起神影院在线观看麻烦 | 污污的网站免费在线观看 | 日韩视频一| 美国黄色毛片女人性生活片 | av 一区二区三区 | 在线不卡视频 | 色欲天天婬色婬香视频综合网 | 欧美aaa毛片免费看 日韩精品一二三区 | 日韩在线观看中文字幕 | 浮力影院在线观看 | 国产亚洲精彩视频 | 成人自拍在线 | 人妻体内射精一区二区三四 | 99在线精品免费视频九九视 | 久久综合一 | 精品久久久久一区二区国产 | 国产精品久久久久久搜索 | 久久精品天天中文字幕人 | 国产精品91久久久久 | 国产成人综合在线 | 免费中文视频 | 天堂一区 | 91在线网站 | 日韩在线观看精品 | 午夜a狂野欧美一区二区 | 国产精品国色综合久久 | 欧美日韩一区不卡 | 色秀视频免费网站在线观看 | 久久6国产| 九九综合九九综合 | 极品美女aⅴ高清在线观看 一级片片 | 精品国产黄a∨片高清在线 亚洲3atv精品一区二区三区 | 91精品天美精东蜜桃传媒入口 | 久久精品国产99国产 | av一区二区三区 | 国产全肉乱妇杂乱视频 | 女猛烈无遮挡性视频免费 |