我想.zshrc在我的~/目录中创建文件的备份,并避免对所有其他项目进行版本控制。如何排除所有子目录及其内容?
例如:
cd ~/subdirectory/ && git status
Run Code Online (Sandbox Code Playgroud)
应该输出:
fatal: Not a git repository (or any parent up to mount point /)
Run Code Online (Sandbox Code Playgroud)
如何实现这一目标?
这是一个常见的解决方案:
例如:
# 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"
Run Code Online (Sandbox Code Playgroud)
你无法让它输出
fatal: Not a git repository (or any parent up to mount point /)
Run Code Online (Sandbox Code Playgroud)
但您可以通过添加文件轻松排除所有其他文件.gitignore,其内容为:
*
!.zshrc
Run Code Online (Sandbox Code Playgroud)
它忽略*除 之外的所有内容 ( ) .zshrc。