无法将除〜-files和.gitconfig之外的所有内容复制到Git -repo

时间:2023-02-05 15:20:59

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 /,而我的Git repo文件在〜/ 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/ 
...
# }}}

The reason is that I want to avoid the files such as

原因是我想避免使用诸如此类的文件

xmonad.hs~   # all ~ -files
.gitconfig

to be added to my Git repo.

被添加到我的Git仓库。

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.

我处理文件的方式开始变得难以控制,因为我找到并将每个文件添加到文件copy_dev-files_to_github是很费时间的。

How do you copy development files to your local Git repo?

如何将开发文件复制到本地Git仓库?

4 个解决方案

#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.

要避免添加某些文件,只需将它们列在.git / info / exclude中即可。

#3


You could use rsync with the --exclude option.

您可以将rsync与--exclude选项一起使用。

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.

将文件添加到存储库后,排除不会使git忽略该文件。尝试在新的存储库上使用.gitignore文件。你也应该在非关键目录中玩游戏,而不是你的主目录。

#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.

要避免添加某些文件,只需将它们列在.git / info / exclude中即可。

#3


You could use rsync with the --exclude option.

您可以将rsync与--exclude选项一起使用。

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.

将文件添加到存储库后,排除不会使git忽略该文件。尝试在新的存储库上使用.gitignore文件。你也应该在非关键目录中玩游戏,而不是你的主目录。