Подтвердить что ты не робот

Отключить предупреждение о отсоединенной головке

В git, если вы проверяете фиксацию напрямую, вы получаете предупреждение о большом жире, начиная с:

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

Хорошо, я намереваюсь находиться в состоянии ОДВ. Однако я использую это в script, и я не хочу этого предупреждения в выходных журналах, но мне нужен нормальный вывод.

Моим "безобразным" решением является выполнение одной и той же команды дважды, сначала с -q, чтобы скрыть предупреждение, и еще один раз, чтобы получить нормальный вывод: HEAD is now at deadbeef... Message, поскольку предупреждение печатается только один раз.

Может ли предупреждение быть отключено, поэтому я могу избежать обходных решений или синтаксического анализа вывода?

4b9b3361

Ответ 1

У вас есть конфигурация для этой задачи:

Установите нужное сообщение, установив значение конфигурации в значение false:

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

detachedHead

Совет, показанный при использовании git -checkout (1), чтобы перейти в состояние отсоединения HEAD, чтобы указать, как создать локальную ветвь после факта.


advice.*

Эти переменные управляют различными необязательными справочными сообщениями, предназначенными для помощи новым пользователям. Все рекомендации. * Переменные по умолчанию равны true, и вы можете сообщить 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.

Ответ 2

Бесстыдно копировать комментарий mjs, чтобы опубликовать его как ответ самостоятельно:

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

Параметр -c advice.detachedHead=false позволит вам подавить предупреждение, не изменяя глобальную конфигурацию. Он будет применяться только к команде.