我正在尝试编写一个 bash 行,它将查看当前文件夹中的所有子目录,并告诉我是否有不包含“.git”的子目录。伪:
for subdir in currentdir
if .git does not exist
print subdir
Run Code Online (Sandbox Code Playgroud)
这是我正在尝试的单行代码,它不起作用并且似乎打印了所有子目录:
find . -maxdepth 1 -type d -execdir $SHELL -c '[ ! -d ".git" ] && echo "not git repo:" {}' $SHELL -c '{}' ';'
Run Code Online (Sandbox Code Playgroud)
我找到了一些解决方案,可以让我打印所有具有 .git 的子目录,就像这个- 我正在尝试做相反的事情。
我究竟做错了什么?这可能吗?
我喜欢写一个 oneliner,它可以从我的 git_repo 文件夹(个人 git 根文件夹)下的克隆存储库中获取所有远程 url,并通过管道传输到一个文件中,我的想法是这样的
cat */.git/config | grep remote.origin.url= >> git_repos.txt
Run Code Online (Sandbox Code Playgroud)
但这当然行不通。
我试图建立一个 git 服务器。我成功设置了 SSH 服务器,现在我尝试设置匿名 git 服务,但它无法正常工作。
\n我从 git 书籍https://git-scm.com/book/en/v2/Git-on-the-Server-Git-Daemon复制了示例 systemd 服务文件,仅更改了我拥有文件的路径:
\n$ cat /etc/systemd/system/git-daemon.service \n[Unit]\nDescription=Start Git Daemon\n\n[Service]\nExecStart=/usr/bin/git daemon --reuseaddr --base-path=/srv /srv/src/\n\nRestart=always\nRestartSec=500ms\n\nStandardOutput=syslog\nStandardError=syslog\nSyslogIdentifier=git-daemon\n\nUser=git\nGroup=git\n\n[Install]\nWantedBy=multi-user.target\nRun Code Online (Sandbox Code Playgroud)\n然后创建一个git用户和组:
\n$ sudo useradd -U --system git\n$ sudo usermod -d /nonexistent git\n$ sudo usermod -s /usr/sbin/nologin git\n$ sudo usermod -c git git\n$ getent passwd git \ngit:x:998:998:git:/nonexistent:/usr/sbin/nologin\n$ groups git\ngit : git\nRun Code Online (Sandbox Code Playgroud)\n然后启用并启动该服务(我将在下面显示该服务处于活动状态并正在运行):
\n$ sudo systemctl enable git-daemon.service\nCreated symlink /etc/systemd/system/multi-user.target.wants/git-daemon.service \xef\xbf\xbd\xef\xbf\xbd\xef\xbf\xbd /etc/systemd/system/git-daemon.service.\n$ sudo systemctl start git-daemon.service\nRun Code Online (Sandbox Code Playgroud)\n然后创建文件来导出存储库:
\n$ touch /srv/src/alx/libalx.git/git-daemon-export-ok\n$ ls …Run Code Online (Sandbox Code Playgroud) 我有
git () { [ $1 = commit ] && command git commit -v "${@:2}" || command git "$@"; }
Run Code Online (Sandbox Code Playgroud)
它使git commithave-v作为默认值,否则传递参数并执行任何git命令。
但它似乎可以缩短?
仅供参考,我正在精简我的.bashrc文件。到目前为止,只有 28 行(大部分仍可读)。
通常,当我在 Git 中提交对子模块的更改时(如果这是唯一的更改),我会将结果提供git diff <submodule-name>给提交消息的正文(在我的 git 配置中diff.submodule设置为log)。所以消息看起来像:
Updated Core Submodule
Submodule Core eaedd3f..0721763:
< Fixed ZA-123: Crash in rendering module
< Merge 'develop' into 'master'
Run Code Online (Sandbox Code Playgroud)
我一直在尝试编写一个脚本来自动执行此操作,我可以将其绑定到我的 git 配置中的别名。要生成上面的文本,理想情况下我想运行一个命令,例如:
$ git submodule-commit Core
Run Code Online (Sandbox Code Playgroud)
这将执行以下操作(大致):
Core在本例中)git commit并提供主题行(Updated $1 Submodule,或者类似的东西,在这个例子中$1是哪里Core)。我没有运气为此编写一个简单的脚本。我对 bash / shell 脚本不是很有经验。任何人都可以帮助提供实现此目的的实现吗?
我正在完成这里的 git 教程:https : //try.github.io/levels/1/challenges/7
它说我必须在 *.txt 周围加上单引号。我以前在使用 linux 时没有见过这个,但认为它很奇怪。我还看到在使用 html 和 php 时使用单引号来确保按字面解释字符串而不是使用特殊字符。
我使用Xubuntu,发现可以使用apt和更新包apt-get。但是我听说程序员通常git在他们的项目中使用不同的版本来管理。那么为什么Xubuntu不用git来处理不同版本的软件呢?
*.xpi我在 git 存储库中有一个存档 ( ) 文件。我怎样才能跟踪档案以获得更有意义的信息git diff呢Binary files ... differ?
这个问题的最佳答案表明,cut可以使用 withtr来根据重复的空格进行剪切
< file tr -s ' ' | cut -d ' ' -f 8
Run Code Online (Sandbox Code Playgroud)
我想要获取目录中多个 Git 存储库的远程地址,并尝试使用以下内容从每个存储库中提取远程 URL 字段:
ls | xargs -I{} git -C {} remote -vv | sed -n 'p;n' | tr -s " " | cut -d ' ' -f1
Run Code Online (Sandbox Code Playgroud)
但是,这会导致(例如)以下输出,其中我可以看到保留了两个连续的空格(Unicode 代码点 32):
origin https://github.com/jik876/hifi-gan.git
origin https://github.com/NVIDIA/NeMo.git
origin https://github.com/NVIDIA/tacotron2.git
Run Code Online (Sandbox Code Playgroud)
(我也使用xargs过tr)
所需的输出是 URL 列表,例如:
https://github.com/jik876/hifi-gan.git
https://github.com/NVIDIA/NeMo.git
https://github.com/NVIDIA/tacotron2.git
Run Code Online (Sandbox Code Playgroud)
我在这里缺少什么?