2016-04-22 61 views
10

禁用警告Git中,如果你籤一個直接提交你得到一個大胖子警告開始:關於分離的頭

"You are in 'detached HEAD' state. You can look around ..." 

這很好 - 我打算在分離的頭的狀態。不過,我正在腳本中使用它,我不希望在輸出日誌中發出此警告,但我確實需要正常輸出。

我現在的「醜陋」解決方法是運行相同的命令兩次,首先用-q隱藏警告,再用一次獲得正常輸出:HEAD is now at deadbeef... Message,因爲警告只打印一次。

警告是否可以禁用,這樣我可以避免變通方法或解析輸出?

回答

17

你有此任務的配置:

由配置值設置爲false,設置所需的信息關:

# turn the detached message off 
git config --global advice.detachedHead false 

detachedHead

所示諮詢時你用git-checkout(1)移動到detach HEAD狀態,指導如何創建al事實後的ocal分支。


advice.*

這些變量控制,旨在幫助新用戶的各種可選的幫助信息。所有的建議*變量默認爲真,並通知Git,你不要被這些設置爲false,需要幫助。

您可以設置任何意見後如下:

git config --global advice.<...> 


pushUpdateRejected 
    Set this variable to false if you want to disable 
     pushNonFFCurrent, 
     pushNonFFMatching, 
     pushAlreadyExists, 
     pushFetchFirst, and 
     pushNeedsForce simultaneously. 

pushNonFFCurrent 
    Advice shown when git-push(1) fails due to a non-fast-forward update 
    to the current branch. 

pushNonFFMatching 
    Advice shown when you ran git-push(1) and pushed matching refs 
    explicitly (i.e. you used :, or specified a refspec that isn’t your 
    current branch) and it resulted in a non-fast-forward error. 

pushAlreadyExists 
    Shown when git-push(1) rejects an update that does not qualify 
    for fast-forwarding (e.g., a tag.) 

pushFetchFirst 
    Shown when git-push(1) rejects an update that tries to overwrite a 
    remote ref that points at an object we do not have. 

pushNeedsForce 
    Shown when git-push(1) rejects an update that tries to overwrite a 
    remote ref that points at an object that is not a commit-ish, or make 
    the remote ref point at an object that is not a commit-ish. 

statusHints 
    Show directions on how to proceed from the current state in the output 
    of git-status(1), in the template shown when writing commit messages in 
    git-commit(1), and in the help message shown by git-checkout(1) when 
    switching branch. 

statusUoption 
    Advise to consider using the -u option to git-status(1) when the command 
    takes more than 2 seconds to enumerate untracked files. 

commitBeforeMerge 
    Advice shown when git-merge(1) refuses to merge to avoid overwriting 
    local changes. 

resolveConflict 
    Advice shown by various commands when conflicts prevent the operation 
    from being performed. 

implicitIdentity 
    Advice on how to set your identity configuration when your information 
    is guessed from the system username and domain name. 

detachedHead 
    Advice shown when you used git-checkout(1) to move to the detach HEAD 
    state, to instruct how to create a local branch after the fact. 

amWorkDir 
    Advice that shows the location of the patch file when git-am(1) fails 
    to apply it. 

rmHints 
    In case of failure in the output of git-rm(1), show directions on 
    how to proceed from the current state. 
+0

謝謝,正是我期待的。 – Zitrax

+0

很酷。高興地幫助 – CodeWizard

+20

要暫時禁用此警告(即不更改配置),請執行諸如'git -c advice.detachedHead = false checkout '之類的操作。 – mjs

10

無恥地抄襲MJS的評論發佈它作爲自己的一個答案:

git -c advice.detachedHead=false checkout <refspec> 

-c advice.detachedHead=false參數可以讓你抑制警告,而無需改變全局配置。它只適用於命令。