Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to make `git add --patch` respond to a single `y` or `n` keystroke?

Tags:

git

git add --patch is an integral part of my Git workflow. The only thing which irritates me about it is constantly having to press the Enter key after each y or n. Is there any way to make Git accept the answer to a question with just a single y or n keystroke?

like image 754
Alex D Avatar asked Sep 13 '15 04:09

Alex D


People also ask

How does git add patch work?

What is “git add -patch” git add -p is short for git add --patch and it is a git option that allows you to make more specific commits. How it works is that it will go through all new changes in your code and display hunks of them at a time for you to decide what you would like to stage or not stage.

What is git add P?

git add -p is basically "git add partial (or patch)" Patch mode allows you to stage parts of a changed file, instead of the entire file. This allows you to make concise, well-crafted commits that make for an easier to read history. This feature can improve the quality of the commits.

What is stage this hunk?

This opens an interactive prompt that allows you to look at the diffs and let you decide whether you want to include them or not. Stage this hunk [y,n,q,a,d,/,s,e,?]? y stage this hunk for the next commit. n do not stage this hunk for the next commit. q quit; do not stage this hunk or any of the remaining hunks.

How do I add a patch to a Git index?

git add –patch. With Git, on the other hand, you first add all the changes you want to be in the next commit to the index via git add (or remove a file withgit rm). Normally, calling git add <file> will add all the changes in that file to the index, but add supports an interesting option: --patch, or -p for short.

What is the difference between --patch and --interactive in Git?

git add –interactive --interactive (or -i) is the big brother of --patch. --patch only lets you decide about the individual hunks in files. --interactive enters the interactive mode, and is a bit more powerful. So powerful that it has its own little submenu:

How do I create a patch of uncommitted changes in Git?

We can create a patch of uncommitted changes by using the Git Diff command. We need to use the Git Format-Patch command to create a patch that contains committed changes. The format-patch command is the preferred way of creating patches.

Why does Git add fail to add Ignored files?

The git add command will not add ignored files by default. If any ignored files were explicitly specified on the command line, git add will fail with a list of ignored files.


1 Answers

That would be the Git configuration option interactive.singleKey.

interactive.singleKey

In interactive commands, allow the user to provide one-letter input with a single key (i.e., without hitting enter). Currently this is used by the --patch mode of git-add(1), git-checkout(1), git-commit(1), git-reset(1), and git-stash(1). Note
that this setting is silently ignored if portable keystroke input is not available; requires the Perl module Term::ReadKey.

That is, in your .gitconfig or equivalent file, add:

[interactive]
    singleKey = true

Or run git config [--global] interactive.singleKey yes, if you like yes better than true and commands better than editors.

like image 128
Ry- Avatar answered Sep 19 '22 14:09

Ry-