4 月 012021
 

Source: How to git-cherry-pick only changes to certain files?

I’d do it with cherry-pick -n (--no-commit) which lets you inspect (and modify) the result before committing:

git cherry-pick -n <commit>

# unstage modifications you don't want to keep, and remove the
# modifications from the work tree as well.
# this does work recursively!
git checkout HEAD <path>

# commit; the message will have been stored for you by cherry-pick
git commit

If the vast majority of modifications are things you don’t want, instead of checking out individual paths (the middle step), you could reset everything back, then add in what you want:

# unstage everything
git reset HEAD

# stage the modifications you do want
git add <path>

# make the work tree match the index
# (do this from the top level of the repo)
git checkout .
6 月 292020
 

Source: How to keep a git branch in sync with master

git checkout master
git pull origin master
git checkout mobiledevicesupport
git merge master

to keep mobiledevicesupport in sync with master

then when you’re ready to put mobiledevicesupport into master, first merge in master like above, then …

git checkout master
git merge mobiledevicesupport
git push origin master

the assumption here is that mobilexxx is a topic branch with work that isn’t ready to go into your main branch yet. So only merge into master when mobiledevicesupport is in a good place

6 月 122020
 

Source: Git: 讓你的代碼回到過去,git reset 與 git revert 的用處

先簡單瞭解檔案存入 repository(倉庫)的流程

Git 簡單來説分為三個區域:

1、工作區(working directory): 我們實際操作的資料夾(檔案)

2、暫緩區(stage snapshot): 將工作區檔案的快照新增到暫存區域

3、git 目錄(.git directory): 提交暫存區域的檔案快照永久地儲存在 Git 目錄

Continue reading »
6 月 092020
 

Source: 使用 git patch 來搬移工作內容

前幾天在改一個專案,因為筆電的設備不夠強大,只能到桌電上開發,兩邊都是開發機,也就沒有用remote 的方式來同步專案。今天,要把那時候的commit 搬回筆電,只好使用git 的patch 移動工作內容,這裡記錄一下整體工作流程和解決衝突的方法。

Continue reading »