~/.zshrc ファイルをgitに追加するには?

~/.zshrc ファイルをgitに追加するには?

.zshrc私の~/ディレクトリにあるファイルのバックアップを作成し、他のすべてのプロジェクトのバージョン管理を避けたいです。すべてのサブディレクトリとその内容を除外する方法は?

たとえば、

cd ~/subdirectory/ && git status

以下を出力する必要があります。

fatal: Not a git repository (or any parent up to mount point /)

この目標を達成する方法は?

ベストアンサー1

一般的な回避策は次のとおりです。

  1. 便利な場所に、好ましくは同じボリュームにサブディレクトリを作成します。
  2. gitで追跡したい.zshrcと他の.*ファイルをこのディレクトリに移動します。通常のコマンドに表示されるか、名前の競合を避けるために名前を変更する必要があります。
  3. 新しいgit-dirのファイルからホームディレクトリへのシンボリックリンクを作成します。
  4. 特定の場所でGitリポジトリを管理します。

たとえば、

# Make a git directory someplace to store your config
git init ~/git/dotfiles

# Move your config to the git directory
mv ~/.zshrc ~/git/dotfiles/zshrc

# Link the config's new location into your $HOME
ln -s ~/git/dotfiles/zshrc ~/.zshrc

# Manage your new repo in its specific location
cd ~/git/dotfiles
git add zshrc
git commit -m"Initial commit"

おすすめ記事