DenCowboy
DenCowboy

Reputation: 15086

How to reduce the git output when checking out a tag

When I checkout a tag I get this output:

λ git checkout REL-6.2.0
Note: checking out 'REL-6.2.0'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at c154795... Set REL-6.2.0 in pom.xml on release/6.2.0 branch.

Is there a way to make the output a bit less or without the git checkout -b proposal? I know I can use something like > /dev/null but I would like some output but just less

Upvotes: 4

Views: 2676

Answers (3)

VonC
VonC

Reputation: 1324577

Note that, before Git 2.34 (Q4 2021), the delayed checkout code path (using filter drivers) in "git checkout"(man) etc... were chatty even when --quiet and/or --no-progress options were given.

See commit 7a132c6 (26 Aug 2021) by Matheus Tavares (matheustavares).
(Merged by Junio C Hamano -- gitster -- in commit f0d7954, 08 Sep 2021)

checkout: make delayed checkout respect --quiet and --no-progress

Signed-off-by: Matheus Tavares

The 'Filtering contents...' progress report from delayed checkout is displayed even when checkout and clone are invoked with --quiet or --no-progress.

Furthermore, it is displayed unconditionally, without first checking whether stdout is a tty.
Let's fix these issues.


The code to show progress indicator in a few code paths did not cover between 0-100%, which has been corrected with Git 2.34 (Q4 2021).

See commit bf6d819, commit 4011224 (09 Sep 2021) by SZEDER Gábor (szeder).
(Merged by Junio C Hamano -- gitster -- in commit df0c308, 20 Sep 2021)

entry: show finer-grained counter in "Filtering content" progress line

Signed-off-by: SZEDER Gábor
Signed-off-by: Ævar Arnfjörð Bjarmason

Let's also initialize the *progress to "NULL" while we're at it.
Since 7a132c6 ("checkout: make delayed checkout respect --quiet and --no-progress", 2021-08-26, Git v2.34.0 -- merge listed in batch #4) we have had progress conditional on "show_progress", usually we use the idiom of a "NULL" initialization of the "*progress", rather than the more verbose ternary added in 7a132c6.

Upvotes: 1

sleske
sleske

Reputation: 83599

Tim Biegeleisen's answer explains how to suppress the message for a single checkout.

If you want to suppress the message permanently, you can use the setting advice.detachedHead:

git config advice.detachedHead false

As usual, this will only affect the current repo. Add option --global to set it globally (for your local user account).

Upvotes: 1

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521339

From the documentation for git checkout, you can use the --quiet flag to suppress certain types of output:

git checkout --quiet    # or just -q

I just checked out a prior commit on a local branch in the detached head state using the --quiet flag and there was no output in the console from Git. Instead, I just saw the new prompt:

/c/users/timbiegeleisen/documents/project ((9e51b34...))

Upvotes: 4

Related Questions