問題タブ [git-alias]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
git - Gitエイリアス:現在のディレクトリをシェルコマンドに渡す方法は?
私は Windows で git bash を使用しています。概念的には次のような git エイリアス コマンドを作成したいと考えています。
が実行されたbash$dir
シェルの現在の作業ディレクトリに展開さgit assume_unchanged_below
れます。
つまり、私が入っC:\somedir\somesubdir
て実行するgit assume_unchanged_below
場合、入力したかのようにしたいでしょうgit ls-files -z C:\somedir\somesubdir | xargs -0 git update-index --assume-unchanged
経由で現在のディレクトリを取得できるようgit rev-parse --show-prefix
です。また、無名関数を使用して引数を渡すことができることも知っていますが、これら 2 つの概念を組み合わせて目的の動作を実現することはできませんでした。
たとえば、これを行うと:
次に、入力できます
And it behaves as expected ($1
is correctly expanded to the current working directory).
However, I don't want to have to manually pass git rev-parse --show-prefix
to the alias, I want it inferred automatically so that I only need to type
have it operate on the current working directory.
I've tried this
but this does not work correctly; $1
in f()
is empty. Presumably this is because the new shell process that is executing f()
has the repository root directory as its current directory.
Is it even possible to do what I'm trying to do in a git alias, or do I need to make an alias in my .bashrc instead to accomplish this?
-------------------- Update with Answer --------------------
$GIT_PREFIX は、元のエイリアスがトリガーされた git シェルからその値を継承するため、$GIT_PREFIX を使用するという @vampire の提案は機能しました。
使いやすさのために装飾を加えた実際の例を次に示します。
git - git commit --amend は危険です
git commit -amend
本当にしたいときに誤って入力することがありgit commit --amend
ます。Git はそれを検出し、私に尋ねます
これは素晴らしいことです。
ただし、時々私が書くgit commit -ammend
と、gitはそれを受け入れてスペルミスを として扱いますgit -a -m "mend"
。そのため、ログメッセージ「修復」でコミットするだけです。
git がそうするのを止める方法を探しています。のエイリアスを定義しようとしましgit commit -ammend
たが、今のところ失敗しました。この問題に対処する方法について何か提案はありますか?