标签: git

打印当前目录中不包含.git的所有子目录

我正在尝试编写一个 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 的子目录,就像这个- 我正在尝试做相反的事情。

我究竟做错了什么?这可能吗?

bash find git test exec

1
推荐指数
1
解决办法
661
查看次数

从子目录中现有的克隆中获取所有 git remote.origin.url

我喜欢写一个 oneliner,它可以从我的 git_repo 文件夹(个人 git 根文件夹)下的克隆存储库中获取所有远程 url,并通过管道传输到一个文件中,我的想法是这样的

cat */.git/config | grep remote.origin.url= >> git_repos.txt
Run Code Online (Sandbox Code Playgroud)

但这当然行不通。

bash pipe git

1
推荐指数
1
解决办法
1147
查看次数

即使 git-daemon-export-ok 存在,git-daemon 也会说“不在白名单中”

我试图建立一个 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\n
Run 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\n
Run 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\n
Run 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
推荐指数
1
解决办法
554
查看次数

从 git 获取分支

假设我想以与获取最新分支相同的方式获取此分支,使用. 我该怎么做?git clone git://github.com/raspberrypi/linux.git

git

0
推荐指数
1
解决办法
86
查看次数

有没有办法让 git commit 将 -v 作为默认值?

我有

git () { [ $1 = commit ] && command git commit -v "${@:2}" || command git "$@"; }
Run Code Online (Sandbox Code Playgroud)

它使git commithave-v作为默认值,否则传递参数并执行任何git命令。

但它似乎可以缩短?

仅供参考,我正在精简我的.bashrc文件。到目前为止,只有 28 行(大部分仍可读)。

shell bash git

0
推荐指数
1
解决办法
59
查看次数

一个可以自动化 git commit 消息内容的 bash 脚本

通常,当我在 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)

这将执行以下操作(大致):

  1. 暂存对指定子模块的任何更改(Core在本例中)
  2. 区分对子模块的更改并存储稍后生成的消息的输出文本
  3. 运行git commit并提供主题行(Updated $1 Submodule,或者类似的东西,在这个例子中$1是哪里Core)。
  4. 将之前存储的差异结果也添加到提交消息中

我没有运气为此编写一个简单的脚本。我对 bash / shell 脚本不是很有经验。任何人都可以帮助提供实现此目的的实现吗?

scripting git

0
推荐指数
1
解决办法
5093
查看次数

'*.txt' 和 *.txt 有什么区别?

我正在完成这里的 git 教程:https : //try.github.io/levels/1/challenges/7

它说我必须在 *.txt 周围加上单引号。我以前在使用 linux 时没有见过这个,但认为它很奇怪。我还看到在使用 html 和 php 时使用单引号来确保按字面解释字符串而不是使用特殊字符。

shell git quoting wildcards

0
推荐指数
1
解决办法
440
查看次数

apt、apt-get 和 git 有什么区别?

我使用Xubuntu,发现可以使用apt和更新包apt-get。但是我听说程序员通常git在他们的项目中使用不同的版本来管理。那么为什么Xubuntu不用git来处理不同版本的软件呢?

git version-control apt software-installation

0
推荐指数
2
解决办法
2155
查看次数

使用 git 跟踪档案

*.xpi我在 git 存储库中有一个存档 ( ) 文件。我怎样才能跟踪档案以获得更有意义的信息git diffBinary files ... differ

git

0
推荐指数
1
解决办法
37
查看次数

如何将 tr 与 xargs 结合并剪切以挤压重复

这个问题的最佳答案表明,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)

(我也使用xargstr

所需的输出是 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)

我在这里缺少什么?

bash git cut tr

0
推荐指数
1
解决办法
111
查看次数

标签 统计

git ×10

bash ×4

shell ×2

apt ×1

cut ×1

exec ×1

find ×1

pipe ×1

quoting ×1

scripting ×1

software-installation ×1

test ×1

tr ×1

version-control ×1

wildcards ×1