无法将除 ~ -files 和 .gitconfig 之外的所有内容复制到 Git -repo
我的开发文件位于 ~/bin/,而我的 Git 存储库文件位于 ~/github/myProject/。 我总是运行以下文件将文件从前一个位置复制到后一个位置:
#!/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/
...
# }}}
原因是我想避免将文件
xmonad.hs~ # all ~ -files
.gitconfig
添加到我的 Git 存储库中。
我处理文件的方式开始变得难以控制,因为查找每个文件并将其添加到文件 copy_dev-files_to_github 中非常耗时。
如何将开发文件复制到本地 Git 存储库?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
为什么要手动复制文件? 当然,您应该将它们添加到存储库中,然后根据需要签出并提交。 我不认为需要移动文件 - 这似乎违背了本地结账的全部目的。
为了避免添加某些文件,只需将它们列在
.git/info/exclude
中即可。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
.另一个解决方案可能是更改开发环境的基础结构,以便首先不需要这些复制步骤。
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.
您可以将
rsync
与--exclude
选项一起使用。例如
You could use
rsync
with the--exclude
option.e.g.
将文件添加到存储库后,排除不会使 git 忽略该文件。
尝试在新存储库上使用 .gitignore 文件。
另外,您可能应该在非关键目录中进行操作,而不是在主目录中。
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.