0

私はこれが単純であることを望んでおり、git を奇妙に構成しただけですが、これは予期された動作ではないと思います。

簡単な git リポジトリを作成しました

> mkdir tmp
> cd tmp
> touch this
> mkdir that
> touch that/what
> git init
Initialized empty Git repository in /home/.../tmp/.git/
> git add this that
> git commit -a -m "initial commit"
[master (root-commit) 679f2ae] initial commit
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 that/what
 create mode 100644 this

次に、新しく作成した git リポジトリでステータスを確認します

> git status
# On branch master
nothing to commit, working directory clean

予想どおり、何もコミットする必要はありません。ただし、ディレクトリ「that」にcdしてステータスを実行すると、次のようになります。

> cd that
> git status
# On branch master
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       deleted:    that/what
#       deleted:    this
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       what
no changes added to commit (use "git add" and/or "git commit -a")

私の質問は、現在の作業ディレクトリがレポのルートではないのに、なぜ git はすべてが削除/追跡されていないと考えるのですか? 私はそれが期待された行動だとは思わなかった。

4

2 に答える 2

0

すべての助けに感謝します-私はこれを理解したと思います. 私のps1変数の別のスクリプトの一部として、「GIT_DIR」環境変数を設定しています(現在のgitブランチをプロンプトに追加するためのもので、非常に便利です)。最初は、GIT_DIR が git によって使用されていないことを確認したと思っていました。少なくともデフォルトでは設定されていませんが、明らかにある程度使用されています。

私が見ている動作はあまり直感的ではないため、gitがこの環境変数をどのように/なぜ使用するのかはまだはっきりしていません。もう少し調査するかもしれません。私のスクリプトは、GIT_DIR を .../.git を保持する最上位ディレクトリに設定します。したがって、どうやら私が別のディレクトリにいる場合、git は現在のディレクトリと *GIT_DIR* ディレクトリとの差分を作成します。なぜそれがすべて役立つのかわかりません。

とにかく、環境変数を GIT_DIR を使用する代わりに MY_GIT_DIR に変更すると、問題が解決したようです。

環境変数が大好き...

于 2013-06-20T20:33:30.180 に答える