Git에서 복제한 원본 저장소 이름 찾기
구문을 사용하여 첫 번째 복제를 수행할 때
git clone username@server:gitRepo.git
로컬 저장소를 사용하여 해당 초기 클론의 이름을 찾을 수 있습니까?
(그러므로 위의 예에서 다음을 찾습니다.gitRepo.git
.)
git config --get remote.origin.url
저장소 루트에서,.git/config
파일에는 원격 리포지토리 및 분기에 대한 모든 정보가 저장됩니다.예제에서는 다음과 같은 것을 찾아야 합니다.
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = server:gitRepo.git
또한 Git 명령어는git remote -v
는 원격 저장소 이름과 URL을 보여 줍니다."origin" 원격 저장소는 대개 로컬 복사본이 복제된 원본 저장소에 해당합니다.
검색 중인 quick Bash 명령어는 원격 저장소의 기본 이름만 인쇄합니다.
가져온 위치:
basename $(git remote show -n origin | grep Fetch | cut -d: -f2-)
또는 푸시할 위치:
basename $(git remote show -n origin | grep Push | cut -d: -f2-)
특히 옵션을 사용하면 명령이 훨씬 빨라집니다.
나는 이것을(를)
basename $(git remote get-url origin) .git
그 말은 다음과 같은 것을 돌려줍니다.gitRepo
. (제거).git
명령의 끝에 다음과 같은 것을 돌려주는 것.gitRepo.git
.)
(참고: Git 버전 2.7.0 이상 필요)
나는 이 질문을 우연히 얻으려다organization/repo
깃허브나 깃랩 같은 깃 호스트의 문자열입니다.
이것이 저에게 효과가 있습니다.
git config --get remote.origin.url | sed -e 's/^git@.*:\([[:graph:]]*\).git/\1/'
사용합니다.sed
의 출력을 대체합니다.git config
조직 및 레포 이름만으로 명령을 수행할 수 있습니다.
뭐 이런 거.github/scientist
캐릭터 클래스와 일치할 것입니다.[[:graph:]]
정규 표현으로
그\1
모든 것을 일치된 문자로만 바꾸라고 sed에게 말합니다.
git repo 이름에 대한 powershell 버전의 명령:
(git config --get remote.origin.url) -replace '.*/' -replace '.git'
git remote show origin -n | ruby -ne 'puts /^\s*Fetch.*(:|\/){1}([^\/]+\/[^\/]+).git/.match($_)[2] rescue nil'
테스트 대상은 다음 세 가지 URL 스타일입니다.
echo "Fetch URL: http://user@pass:gitservice.org:20080/owner/repo.git" | ruby -ne 'puts /^\s*Fetch.*(:|\/){1}([^\/]+\/[^\/]+).git/.match($_)[2] rescue nil'
echo "Fetch URL: Fetch URL: git@github.com:home1-oss/oss-build.git" | ruby -ne 'puts /^\s*Fetch.*(:|\/){1}([^\/]+\/[^\/]+).git/.match($_)[2] rescue nil'
echo "Fetch URL: https://github.com/owner/repo.git" | ruby -ne 'puts /^\s*Fetch.*(:|\/){1}([^\/]+\/[^\/]+).git/.match($_)[2] rescue nil'
git ls-remote --get-url | xargs basename # gitRepo.git
git ls-remote --get-url | xargs basename -s .git # gitRepo
# zsh
git ls-remote --get-url | read
print $REPLY:t # gitRepo.git
print $REPLY:t:r # gitRepo
명확하게 하기 위해 편집됨:
remote.origin.url이 protocol://auth_info@git_host:port/project/repo.git 형식인 경우 값을 가져옵니다.작동하지 않을 경우 첫 번째 컷 명령의 일부인 -f5 옵션을 조정합니다.
protocol://auth_info@git_host:port/project/repo.git의 remote.origin.url 예제의 경우 cut 명령에 의해 생성된 출력에는 다음이 포함됩니다.
-f1: protocol: -f2: (공백) -f3: auth_info@git_host:port -f4: project -f5: repo.git
문제가 있는 경우 출력을 살펴봅니다.git config --get remote.origin.url
원래 리포지토리를 포함하는 필드를 확인하는 명령입니다.remote.origin.url에 .git 문자열이 없는 경우 두 번째 cut 명령에 파이프를 생략합니다.
#!/usr/bin/env bash
repoSlug="$(git config --get remote.origin.url | cut -d/ -f5 | cut -d. -f1)"
echo ${repoSlug}
언급URL : https://stackoverflow.com/questions/4076239/finding-out-the-name-of-the-original-repository-you-cloned-from-in-git
'programing' 카테고리의 다른 글
array.prototype.에는 vs.배열.원형.indexOf (0) | 2023.09.25 |
---|---|
TEXT 형식의 열을 VARCHAR로 변환하는 방법은? (0) | 2023.09.25 |
IE10+의 AngularJS, 자리 표시자가 있는 텍스트 영역 "잘못된 인수"입니다. (0) | 2023.09.25 |
"원격 추적 지점 '출발/개발'을 개발에 통합하는 이유는 무엇입니까? (0) | 2023.09.25 |
MySql Workbench 설치 관리자를 사용하려면 Visual C++ 2015 Redistributable Package를 설치해야 하지만 이미 설치되어 있습니다. (0) | 2023.09.25 |