[程式開發通用]repo & git & patch/diff 的教學(一次搞懂版本管控與分支管理)

出處:http://kunhsien.blogspot.tw/2014/03/patch-diff.html

Repo:
repo安裝建置參考:

http://source.android.com/source/downloading.html

照上述網址的開頭架設Repo的環境,內容如下:

Installing Repo

Repo is a tool that makes it easier to work with Git in the context of Android. For more information about Repo, see the Developingsection.
To install Repo:
  1. Make sure you have a bin/ directory in your home directory and that it is included in your path:
    $ mkdir ~/bin
    $ PATH=~/bin:$PATH
  2. Download the Repo tool and ensure that it is executable:
    $ curl http://commondatastorage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
    $ chmod a+x ~/bin/repo

從nas上用repo來下載source code:
1.repo init
2.repo init -u ssh://git-user@ip_address/volume1/git-repo/sourcecode_package/manifest2.git
3.repo sync
如此,就能將nas上的source code下載下來
======================================
Git:
說明:git是時下蠻多人用的版本控管軟體,有別於svn的集權式控管 git充滿彈性,且人人都是皇帝
有關於git的教學可參考下列reference:

ubuntu底下安裝git:sudo apt-get install git
安裝好之後連gitk(圖形介面管理工具)都幫你裝好了
此外,透過在$HOME目錄下的.gitconfig 編輯[alias]可以自訂一些簡化指令
[alias]
  co = checkout
  ci = commit
  st = status
  br = branch
  hist = log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short
另外也可在.profile自訂git的命令列別名
alias go='git checkout '

可以使用gitk –all & (加上&即為背景執行)
就可以看到整個分支的圖形管理
可以依序下一些command來做一些管控
git status 來看目前的狀態 會告知你版本 在第幾版以及修改哪些檔案
git branch -av  先檢視目前所有版本分支
git branch branch_name 建立一個新的branch
git branch ‘name’ ‘branch_name’ 建立一個branch 並鏈結到既有branch_name

git  checkout -b xxx branch name

git branch -m old_name new_name (-M為強制更名) 更改branch名稱
git branch -d 刪除 local branch
git checkout  切換branch到新的branch就可以開始改source code
====== Source code修改完成後 ==========
git add -u 新增修改的檔案

git add 檔名 單一檔案新增
git mv ‘檔案’ ‘檔案移動資料夾’  告訴git 檔案被移動到檔案移動資料夾裡

====== Source code 取消add ==========

git reset HEAD [file_name]  單一檔案取消git add

git reset HEAD    全部檔案取消git add(不指定檔名)

git commit -m ‘新增commit’   進版將commit更新

git commit   為預防手殘 可先進入編輯 再commit

git revert HEAD  復原已送交的修改

git tag -a v0.1 -m ‘ver0.1’ 上版號標簽

git tag -d ‘標簽名稱’ 移除標簽,會順便回收

git push 遠端網址 本地branch_name    將本地端git 的專案push到遠端伺服器集中管理

//開發者階段結束

//////////////////管理者階段的開始 (merge) /////////////////////

git merge master

ssh xxxxx 連線到遠端nas伺服器

/*GIT IMMERSION 練習區*/
http://blog.faq-book.com/Article-Translation/git_tutorial-master/
一.前置作業:
1.設定git的使用者名稱及其電子郵件
git config –global user.name Jason
git config –global user.email “[email protected]
2.換行字元的偏好設定(Windows 因為處理換行字元和 Unix like 不同會造成 Git 誤判成有修改因此需多設定)(for UNIX/OSX):
git config –global core.autocrlf input
git config –global core.safecrlf true
1.建立測試資料夾:mkdir test
2.切換到測試資料夾 -> cd test
3.新增一個c文件並嘗試加入一些代碼至其中:touch a.c &vim a.c
4.初始化git專案:git init
5.將新變更的檔案加入到git中:git add a.c
6.設定commit -> git commit -m “first commit”
7.觀看git目前的狀態 -> git status
8.修改檔案 vim a.c
9.輸入git add a.c 再再鍵入git status
10.此外若是整個目錄下多個檔案可以使用 -> git add .
11.git單行記錄格式:git log –pretty=oneline12.
13.  目前做到第11章
14.
15.
/*GIT IMMERSION 練習區*/

patch & diff:

reference:http://blog.longwin.com.tw/2013/08/linux-diff-patch-learn-note-2013/

一:製作 patch 檔 

代碼: 選擇全部
diff -Nur abc-1.9(舊版) abc-2.0(新增) >     (大於)patch_abc_1.9_to_2.0.diff


這樣就會製作出 abc 這個軟體從 1.9 到 2.0 的所有變化,存成檔案。
寄給開發者之前還可以看看 patch 裡是否有多餘無用的資訊,例如 tab 變成 space、多了幾行空白之類的…總之 patch 越乾淨越好,不要多改一些有的沒的。
乾淨的 patch 會讓開發者更容易接受。



二:打補丁(apply patch)

代碼: 選擇全部

cd abc-1.9.9
patch -p1 <patch_abc_1.9_to_2.0.diff

將1.9跟2.0 diff出來的差異配置檔 寫到1.9中 p1代表省略一層

省略幾層要視當時diff位置而定
這樣就會把 abc-2.0新增的差異內容 加到abc-1.9中 




三:大量檔案改變編碼
你有大量 Big5 檔案想換成 UTF-8 嗎?

代碼: 選擇全部
mkdir foobar.utf8
diff -Nur foobar.utf8 foobar.big5 > foobar_big5.diff
iconv -f CP950 -t UTF-8 -c foobar_big5.diff > foobar_utf8.diff
cd foobar.utf8
patch -p1 < ../foobar_utf8.diff


這樣就會把 foobar.big5 裡所有的檔案(含子目錄裡的檔案、子目錄的子目錄裡的檔案…) 
轉換成 UTF-8,且所有目錄結構完全不變。 


同樣道理,這個技巧可以用於簡繁轉換、dos2unix 文件格式轉換、各種文件格式互轉…

未經允許不得轉載:GoMCU » [程式開發通用]repo & git & patch/diff 的教學(一次搞懂版本管控與分支管理)