2

在文件夹树中:

Hard_Disk:
- Applications
- Users:
- - User-1_folder
- - User-2_folder:
- - - - .bash_history
- - - - .bash_profile
- - - - .bashrc
- - - - .gitconfig
- - - - .gitignore_global
- - - - .ssh
- - - - Applications
- - - - Desktop
- - - - ...
- - User-3_folder
- Library
- System

我可以对我的.bash_profile或与 相同文件夹中的任何其他文件进行版本控制.gitconfig吗?

在 User_folder 中启动 git 存储库是否安全?

忽略所有文件夹及其.gitconfig本身,只是为了保持一些设置正常!

4

1 回答 1

4

This is one way to go about it, although not so clean it does the job without the hassle of maintaining symlinks on each machine:

cd ~
git init

# Ignore everything except .bash_profile and .gitignore
echo '/*' > .gitignore
echo '!/.bash_profile' >> .gitignore
echo '!/.gitignore' >> .gitignore

# Only .bash_profile and .gitignore would be added
git add .

# Commit
git commit -m "Adding .bash_profile and .gitignore"

# Add the remote details and push the master branch into the remote
git remote add <REMOTE-NAME> <REMOTE-URL>
git push <REMOTE-NAME> master

One thing you got to be careful is when you're cloning this repo on another machine, git clone will error if the destination directory is not empty. So you could do something like this to initially set it up:

mkdir -p ~/temp-git-dir
cd ~
git clone <REPO-URL> ~/temp-git-dir
mv ~/temp-git-dir/.git .
rm -rf ~/temp-git-dir
于 2013-04-16T17:24:31.250 回答