[英]How to make Git pull use rebase by default for all my repositories?
[英]How to make magit pull to have rebase option by default?
我最近開始在emacs中使用magit包,它非常實用且方便。 我想做幾個調整。
如何使magit pull始終具有rebase選項? 目前它顯示了交換機,我必須選擇-r --rebase。 在我的開發過程中,我們總是反思。
我使用gtags + global進行代碼瀏覽。 在magit pull,如果我能有一個鈎子再次重建gtags那將是很好的。 git拉成功后有鈎子嗎?
我不知道任何特定於Magit的設置,但您可以相應地配置git
本身:
git config --global pull.rebase true
我嚴格建議不要在全球范圍內啟用此設置。
正如我在評論中所說,你應該真正改變你的開發過程,這樣就不需要在git pull
上合並/變基。 不要在共享分支上工作,而是始終為您的工作創建自己的功能分支,並在需要時顯式合並。
然后,您可以在存儲庫中顯式配置各個共享分支以進行重新定位,例如
git config --local branch.my-fancy-feature.rebase true
至於鈎子, git pull
沒有特定的鈎子。 但是,在對樹的其他更改中更新標記文件也沒有什么害處,因此您可能只是post-rewrite
(對於git rebase
)和post-merge
(對於git merge
)鈎子。
有關此類設置的詳細信息,請參閱Tim Pope的帖子Effortless Ctags with Git 。
將以下內容添加到.emacs
:
(defun magit-key-mode--add-default-options (arguments)
(if (eq (car arguments) 'pulling)
(list 'pulling (list "--rebase"))
arguments))
(advice-add 'magit-key-mode :filter-args #'magit-key-mode--add-default-options)
此代碼將執行您想要的操作,並可以輕松地為更多模式添加默認選項:
(defun magit-key-mode--add-default-options (arguments)
(let* ((mode (car arguments))
(options (cadr arguments))
(default-options (cdr (assoc mode my/magit-default-options))))
(list mode (delete-dups (delq nil (append options default-options))))))
(setq my/magit-default-options
`(
(pulling "--rebase")
))
(advice-add 'magit-key-mode :filter-args #'magit-key-mode--add-default-options)
注意:這應該是對doublep答案的編輯,但是4-out-of-4 wonks拒絕編輯。 其中沒有一個人甚至觸及過Emacs.SE,也沒有在他們的SO或LinkedIn個人資料中提及過Emacs或Lisp。 顯然,不了解有關語言的人不應被賦予拒絕編輯的權力。
我來到這里尋找這個問題的答案,找到了doublep的答案,通過使代碼更清晰和可擴展來改進它,並花費我自己寶貴的時間將改進貢獻給社區,只是讓那些不喜歡的人擊落它甚至不知道他們在做什么。 每當這種情況發生時(而且,到目前為止,它每次都發生過),我想知道為什么我在浪費時間為這個網站做貢獻。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.