禁用关于分离的HEAD的警告 [英] Disable warning about detached HEAD

查看:675
本文介绍了禁用关于分离的HEAD的警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在git中,如果您直接签出提交,则会收到一个大的警告:

 您处于'分离HEAD'状态,你可以环顾四周...

没关系 - 我打算分开HEAD状态。然而,我正在脚本中使用它,我不希望在输出日志中发出此警告,但我确实需要正常输出。



现在我的丑陋解决方法是运行相同的命令两次,首先用-q隐藏警告,再用一次获得正常输出: HEAD现在处于deadbeef ... Message ,因为警告只能打印一次。



警告是否可以禁用,这样我可以避免变通方法或解析输出?

解决方案

您有这项任务的配置:



通过将config值设置为false来设置所需的消息:

 #将分离的消息关闭
git config --global advice.detachedHead false




detachedHead



当您使用git-checkout(1)移动到detach HEAD状态时,显示的建议指示如何在







advice。*



这些变量控制各种帮助新用户的帮助信息。所有的建议。*变量默认为true,你可以通过设置为false来告诉Git你不需要帮助:

你可以在建议后设置以下任何一项:

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


pushUpdateRejected
如果要禁用
pushNonFFCurrent,
pushNonFFMatching,
pushAlreadyExists,
pushFetchFirst,请将此变量设置为false ,和
pushNeedsForce同时。

pushNonFFCurrent
当git-push(1)因当前分支的非快进更新
而失败时显示的建议。

pushNonFFMatching
当您运行git-push(1)并显式推送匹配ref
时显示的建议(即,您使用了:,或指定了不是$ b的refspec $ b当前分支),并导致一个非快进错误。

pushAlreadyExists
当git-push(1)拒绝不符合
快速转发条件的更新时(例如,标签)时显示。

pushFetchFirst
当git-push(1)拒绝试图覆盖指向我们没有的对象的
远程引用的更新时显示。

pushNeedsForce
当git-push(1)拒绝尝试覆盖指向不是commit-ish的对象的
远程引用的更新时显示,或者使
远程引用指向一个不是commit-ish的对象。

statusHints
在git-status(1)的输出
中显示如何在当前状态下进行操作的方向,在以$ b $写入提交消息时显示的模板中b git-commit(1)和git-checkout(1)在
切换分支时显示的帮助信息中。

statusUoption
建议考虑在命令
花费2秒以上枚举未跟踪文件时,使用-u选项指示git-status(1)。

commitBeforeMerge
当git-merge(1)拒绝合并以避免覆盖
本地更改时显示的建议。

resolveConflict
当冲突阻止执行操作
时,各种命令显示的建议。

implicitIdentity
当您的信息
从系统用户名和域名中被猜出时,如何设置您的身份配置的建议。

detachedHead
当你使用git-checkout(1)移动到detach HEAD
状态时,显示的建议告诉如何在事实之后创建一个本地分支。

amWorkDir
当git-am(1)失败
应用它时显示补丁文件位置的建议。

rmHints
如果输出git-rm(1)失败,请在
上显示如何从当前状态继续。


In git if you checkout a commit directly you get a big fat warning starting with:

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

It's fine - I intend to be in detached HEAD state. However I am using this in a script and I don't want this warning in the output logs but I do want the normal output.

My "ugly" workaround now is to run the same command twice, first with -q to hide the warning, and one more time to get the normal output: HEAD is now at deadbeef... Message since the warning is only printed once.

Can the warning be disabled so I can avoid workarounds or parsing the output ?

解决方案

You have the config for this task:

Set the desired message off by setting the config value to false:

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

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.


advice.*

These variables control various optional help messages designed to aid new users. All advice.* variables default to true, and you can tell Git that you do not need help by setting these to false:

You can set any of the following after the advice:

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.

这篇关于禁用关于分离的HEAD的警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆