Windows/bash 中出现意外的问号

发布于 2025-01-20 12:09:31 字数 659 浏览 1 评论 0原文

我正在尝试使用Windows上的Mingw Bash自动在Windows上“存档”一些本地分支。

我在txt文件(branches_to_be_archived.txt)上复制并粘贴了git分支

#!/bin/bash
BRANCH_NAME=$1
echo "Branch name is $BRANCH_NAME"
git tag archive/$BRANCH_NAME $BRANCH_NAME
git branch -D $BRANCH_NAME

内容从文件中,

#!/bin/bash
FILE=./branches_to_be_archived.txt
LINES=$(cat $FILE)
for LINE in $LINES
do
    ./archive_branch.sh.txt $LINE
done

我插入了一些回声打印,它们还可以,但是执行git命令会引起这样的错误:

fatal: Failed to resolve '[actual name of the branch]?' as a valid ref.

拖尾?在任何地方都没有显示。

有什么办法避免在最后有这个问号吗?

I'm trying to automatically "archive" some local branches on Windows using the MinGW Bash on Windows.

I copy and pasted the content of git branch on a txt file (branches_to_be_archived.txt) and then I wrote:

A script to archive a single branch

#!/bin/bash
BRANCH_NAME=$1
echo "Branch name is $BRANCH_NAME"
git tag archive/$BRANCH_NAME $BRANCH_NAME
git branch -D $BRANCH_NAME

A script to archive every branch from a file

#!/bin/bash
FILE=./branches_to_be_archived.txt
LINES=$(cat $FILE)
for LINE in $LINES
do
    ./archive_branch.sh.txt $LINE
done

I inserted some echo prints and they are ok but executing git commands will raise an error like this:

fatal: Failed to resolve '[actual name of the branch]?' as a valid ref.

With a trailing ? that is not shown anywhere.

Any way to avoid having this question mark at the end?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

游魂 2025-01-27 12:09:31

事实上,这是一个尾行字符问题(Win CRLF 和 Linux LF)。

我通过使用 Notepad++ 并设置 EOL -> 解决了这个问题Linux (LF) 但我认为分支列表文件的 dos2unix 工作得很好

Indeed, it was a endline characters issue (Win CRLF and Linux LF).

I solved by using Notepad++ and setting EOL -> Linux (LF) but I think that dos2unix for branches list file works just fine

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文