谢谢你的阅读!
我开始用git和GitHub设置我的dotfiles配置,遇到了一个问题:我使用我的$HOME作为我的git工作树,并在我的$HOME/.dotfiles-directory中使用.git-directory,使用别名:
alias dotfiles="git --git --git-dir=$HOME/.dotfiles/.git/ --work-tree=$HOME"我在GitHub上创建了一个new库,并在那里添加了许可证和自述文件。当我像这样克隆我的仓库时:
git clone \ $HOME/.dotfiles许可证和自述文件位于.dotfiles-directory中,但是命令:
dotfiles status将它们列为<#>删除!
我<#>do不想要$HOME-directory中的许可证和自述文件。他们应该呆在$HOME/.dotfiles-directory的地方。
我能做些什么?
发布于 2023-02-18 07:25:17
实际上,在主分支中有许可和自述文件是可能的,github和gitlab将遵守它们(显示在github或gitlab中的项目主页上),但不显示在主目录中。最简单的解决办法是将自述文件放在项目主页的.github文件夹中,但它只适用于github。
但是,我在gitlab和github的项目主页上展示了许可证和自述文件,实际上是这样的:
首先,为xadf启动一个裸的git,并在没有自述和/或许可的情况下进行初始提交,并创建别名。这个别名可以是你想要的任何东西。( dotfiles),但是我使用gitdf,所以更容易输入。
# Initialize a bare git directory
git init --bare $HOME/.dotfiles
# Sets up an alias so you don't have to type long commands
alias gitdf='git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
# Adds a remote where you'd push your changes
gitdf remote add origin git@gitlab.com:yourusername/dotfiles.git
# Do not display untracked files (it would be a ton of untracked files in an actual home tree
gitdf config status.showUntrackedFiles no或者,如果您已经有了一个dotfiles存储库,您可能希望将其复制到您的家中:
# Clone existing repo with separate git directory (here it is ~/.dotfiles), and the work tree in a separate, temporary directory .dotfiles-temp
git clone --separate-git-dir=$HOME/.dotfiles https://github.com/yourusername/dotfiles.git .dotfiles-temp
# Copy the content of the temporary work tree to ~/
rsync --recursive --verbose --exclude '.git' .dotfiles-temp/ $HOME/
# Remove the temporary work tree
rm --recursive .dotfiles-temp
# Sets up an alias so you don't have to type long commands
alias gitdf='git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
# Sets remote directory
gitdf remote set-url origin git@github.com:yourusername/dotfiles.git请注意,您可能需要将别名添加到您的.bashrc中,以便每次登录时都保持别名。
这是真正的树枝,你会在你真正的家树中退房。比如说,一个home分支。
# Make branch 'home'
gitdf checkout -b home
# You may need to also add the branch to gitlab or github
gitdf push --set-upstream origin home然后,在分支母版中,您可以安全地添加一个自述文件和许可(如果您愿意)。这将仅用于在gitlab或github的项目主页中提供信息。此文件将不会出现在分支主页的提交历史记录中,并且<#>should永远不会引入到您的主分支中。
# Switch back to branch 'master'
gitdf checkout master
# Make readme and license
touch ~/LICENSE ~/README.md
# Add them to your bare git repo
gitdf add LICENSE README.md
# Commit
gitdf commit
# Push
gitdf push进行更改
然后回到分支home,这应该是您的dotfile的实际签出分支,其中自述文件或许可文件在其提交历史记录中从未出现过。
gitdf checkout home之后,配置文件的更改仅从home分支进行,或者从分支home派生的任何分支。您可能需要偶尔(或常规地)将它们合并以掌握:
# Go to branch master
gitdf checkout master
# merge branch home to branch master
gitdf merge home
# push to remote
gitdf push因为分支主页没有LICENSE和README.md,所以合并不会导致冲突。
但你不应该反过来做(例如)。因为它还会将LICENSE和README.md添加到您的工作主目录中。
中的多个机器特定配置
额外的好处是,您可能希望将分支home派生为其他特定用途(例如,在本应基于home但具有特定于工作的信任的分支work中):
# Check if we're in branch home
gitdf status -sb
# Checkout to branch home if we are not
gitdf checkout home
# Note that the -b flag means make branch if it does not exist
gitdf checkout -b work
# Add new branch to remote
gitdf push --set-upstream origin work
# Configure or add work-specific changes then commit
gitdf add .config/work/related/configfile
gitdf commit
# Push to remote
gitdf push稍后,当您对home分支进行更改时,您所要做的就是在您的work分支中也进行更改:
# move to branch work
gitdf checkout work
# merge branch home to branch home
gitdf merge home
# Push to remote
gitdf push如果您有其他分支(所有分支都来自home,这意味着您必须从分支home开始并创建新分支),比如laptop,您也可以在必要时合并到它们的主分支。如果需要,还可以将在那里所做的更改合并到home。
不过,实际上,我建议您从home中进行共享信任,然后将它们合并到必要的分支和master。
因此,您可以像这样可视化合并方向:
master < home <> work
<> laptop只有把家合并到主人,工作,或笔记本电脑,或者从工作,笔记本电脑,到家里,但绝不合并主人到家。
作为一个无耻的插件,您可以看到我是如何在我的dotfiles存储库中设置这个git别名方法的。它是上述步骤的一个更完善和中等复杂的实现。要安装它,我所要做的就是下载安装程序和控制器脚本(沙德夫),使其可执行,并将其放在我的路径中的某个地方。
# Make directory, if it isn't present already
mkdir -p ~/.local/bin
# Download the executable into your local bin directory
wget -O ~/.local/bin/xadf https://gitlab.com/heno72/xadf/-/raw/master/.local/bin/xadf
# Make it executable
chmod +x ~/.local/bin/xadf
# Export path to local bin if it isn't set up already
PATH=~/.local/bin:$PATH
# Install xadf minimally
xadf --minimal-install脚本可以处理步骤1(复制),签出到一个工作分支(默认为trunk,相当于上面示例中的home分支),包括生成配置文件以供将来在~/.config/xadf中使用(别名和一些函数):
# initialize, configure, load, and manage
xadf --init-bare --seat ~/.dotfiles
xadf --custom-install --seat ~/.dotfiles
. ~/.bashrc
xadf config status.showUntrackedFiles no或者,如果您已经在远程中拥有自己的现有git存储库:
# Clone and configure from a custom url, load, and manage
xadf -i -s git@gitlab.com:heno72/xadf-gb.git --seat ~/.dotfiles
. ~/.bashrc
xadf status -sb如果您的主文件夹中已经有了裸露的git目录,则可以使用xadf来管理它们:
xadf --custom-install --seat ~/.dotfiles
. ~/.bashrc安装后( .bashrc来源),我可以像使用任何git命令一样使用脚本:
# Adds a new config file to tracked file
xadf add .config/new/config/file
# Commit changes
xadf commit
# Push changes to remote
xadf push
# Change working branch
xadf checkout newbranch或某些预先确定的行动:
xadf -l # list all tracked files
xadf -l .config # list all tracked files in ~/.confighttps://unix.stackexchange.com/questions/621135
复制相似问题