Zi 字媒體
2017-07-25T20:27:27+00:00
使用git pull時,git會將本機的repository和遠端的repository做merge,當merge數量一多git的樹狀圖就會非常混亂。
為了避免這樣的狀況,當我們修改小地方時,就不要再讓repository merge一次,透過rebase讓樹狀不會亂長
指令:
git pull --rebase
rebase會做四件事
1.暫存一份本機repository從上次pull之後再修改的部份
2.將本機repository rollback到上一次pull的狀況
3.套用遠端的變更
4.套用暫存下來的本地變更
rebase branch
git rebase
當遇到檔案內容衝突時,修改並git add(不要commit)之後,要再下以下指令繼續rebase:
git rebase --continue
如果想要預設pull就使用rebase,可以修改.git/config
[branch "master"]
remote = origin
merge = refs/heads/master
#master branch 預設使用rebase
rebase = true
[branch]
#所有branch預設都用rebase
autosetuprebase = always
另外rebase也可以透過Interactive mode自動更改commit的順序及內容
#該commit之後的commit都要重新整理
git rebase -i
# 可以選擇的option
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# 若是使用edit,記得修改完檔案後git add(不要commit)並再下git rebase --continue
# 設定上出問題,可以到.git/rebase-merge/git-rebase-todo,並再重下git rebase
Categories: Git
分類
Android
AngularJS
Chrome
Database
MySQL
DataStructure
Editor
Vim
Firefox
Git
Hadoop
Language
Go
Java
JavaScript
jQuery
jQueryChart
Node.js
Vue
PHP
Laravel
ZendFramework
Python
Mac
Network
Cisco
DLink
Juniper
Oauth
Server
Apache
Share
Unix
FreeBSD
Linux
WebDesign
Bootstrap
CSS
HTML
Wordpress
Search
搜尋:
寫了
5860316篇文章,獲得
23313次喜歡