简体   繁体   English

我如何列出 shell 脚本中的所有分支列表

[英]How can i list all branch lists in shell script

I am coding a script that makes a comparisson between two repositories from two different cotroler systems (svn and git) for a work im doing.我正在编写一个脚本,该脚本对来自两个不同控制系统(svn 和 git)的两个存储库进行比较,以用于我正在做的工作。 In svn i just took the link of the repository that is the same as i would need to checkout (pull) the branch or even the trunk (master) of it.在 svn 中,我只是获取了存储库的链接,这与我需要检出(拉)分支甚至它的主干(主)相同。 But in git things look different and i only have a ssh link to do it, and for what i've seen so far nothing is really helping, i even tried to make a variable that was supose to go to where the ".git" archive is setup in my machine to do the git branch -a from there, cause i seen it works when i'm inside the directory using the "WSL".但是在 git 中,事情看起来不一样,我只有一个 ssh 链接可以做到这一点,到目前为止我所看到的没有任何帮助,我什至试图制作一个应该去“.git”的地方的变量存档在我的机器中设置为从那里执行 git branch -a,因为我看到它在我使用“WSL”进入目录时工作。

in svn i did it like this在svn中我是这样做的

svn_trunk="https checkout link"
BRANCHES="branches"
TAGS="tags"
TRUNK="trunk"

# Branchs Configuration
SVN_BRANCHES=$BASE_SVN/$BRANCHES
SVN_TAGS=$BASE_SVN/$TAGS
SVN_TRUNK=$BASE_SVN/$TRUNK
echo '[RUN] svn ls ' $SVN_BRANCHES
svn ls $SVN_BRANCHES
echo '[RUN] git ls ' $GIT_LIST
git tag -n $GIT_LIST

the out puts asks for my credentials and then it shows all the branches from it, but i dont know how to make something similar in git way.输出询问我的凭据,然后显示它的所有分支,但我不知道如何以 git 方式制作类似的东西。

I tried doing somethin similar like:我尝试做类似的事情:

GIT_BRANCHES=$GIT_URL/$BRANCHES
GIT_TAGS=$GIT_URL/$TAGS
GIT_TRUNK=$GIT_URL/$MASTER

echo '[RUN] git ls ' $GIT_BRANCHES
git branch -a $GIT_BRANCHES

echo '[RUN] git ls ' $GIT_TAGS
git tag -n $GIT_TAGS

and i was expecting that the exit listed all branches and tags out of the repository, what it isnt doing.我期待出口列出存储库中的所有分支和标签,它没有做什么。

If you run the git commands in a repository, then git branch -a will output all the branches.如果您在存储库中运行git命令,则git branch -a将输出所有分支。 For example, check the output of these commands:例如,检查这些命令的输出:

git branch -a > mybranches.txt
cat mybranches.txt 

Note that you don't need to specify anything after the git branch -a command if the current directory is a git repository.请注意,如果当前目录是 git 存储库,则无需在git branch -a命令后指定任何内容。

But if your current directory (pwd) is not your git repository, then you may run the following command (note the -C option and a path):但是,如果您当前的目录 (pwd) 不是您的 git 存储库,那么您可以运行以下命令(注意-C选项和路径):

git -C "PATH/TO/GIT-REPOSITORY" branch -a

The syntax is awkward.语法很尴尬。 You have to add -C PATH before the actual branch -a command.您必须在实际branch -a命令之前添加-C PATH

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM