问题
I have my dev files at ~/bin/, while my Git repo files at ~/github/myProject/. I always run the following file to copy files from the former location to the latter one:
#!/bin/zsh
# editors# {{{
cp /Users/Masi/.emacs /Users/Masi/gitHub/MasiDvorak/
cp /Users/Masi/bin/editors/emacs/* /Users/Masi/gitHub/MasiDvorak/editors/emacs/
cp /Users/Masi/.vimrc /Users/Masi/gitHub/MasiDvorak/
cp /Users/Masi/bin/editors/vim/* /Users/Masi/gitHub/MasiDvorak/editors/vim/
# }}}
# shells# {{{
cp /Users/Masi/.bashrc /Users/Masi/gitHub/MasiDvorak/
cp /Users/Masi/.profile /Users/Masi/gitHub/MasiDvorak/
cp /Users/Masi/.zshrc /Users/Masi/gitHub/MasiDvorak/
# }}}
# programming# {{{
cp /Users/Masi/.screenrc /Users/Masi/gitHub/MasiDvorak/
cp /Users/Masi/.Xmodmap /Users/Masi/gitHub/MasiDvorak/
cp /Users/Masi/.xmonad/xmonad.hs /Users/Masi/gitHub/MasiDvorak/.xmonad/
cp /Users/Masi/.gdbinit /Users/Masi/gitHub/MasiDvorak/
cp /Users/Masi/.xmonad/xmonad.hs /Users/Masi/gitHub/MasiDvorak/
...
# }}}
The reason is that I want to avoid the files such as
xmonad.hs~ # all ~ -files
.gitconfig
to be added to my Git repo.
My way of coping the files starts to be challenging to be controlled, since it is time-consuming for me to find and add each file to the file copy_dev-files_to_github.
How do you copy development files to your local Git repo?
回答1:
Another solution might be to change the infra structure of your development enviroment, so that these copying steps aren't needed in the first place.
回答2:
Why are you manually copying files around at all? Surely you should just add them to the repo, then check out and commit as necessary. I don't see the need to move the files around - that seems to defeat the whole purpose of a local checkout.
To avoid adding certain files, just list them in .git/info/exclude
.
回答3:
You could use rsync
with the --exclude
option.
e.g.
rsync --exclude='.gitconfig' --exclude='*~' /Users/Masi/ /Users/Masi/gitHub/MasiDvorak/
回答4:
Once a file is added to the repository, excluding will not make git ignore that file.
try using a .gitignore file on a fresh repository.
also you should probably play around in a noncritical directory, rather than your home directory.
来源:https://stackoverflow.com/questions/1048827/unable-to-copy-all-but-files-and-gitconfig-to-git-repo