자식에서 여러 원격 지점 삭제
부지런히 150 개가 넘는 현지 지사를 중앙 리포지토리로 푸시 한 팀원이 있습니다. 고맙게도 모두 같은 접두사가 있습니다. 그 접두사를 사용하면 git 명령이나 멋진 작은 쉘 스크립트가 있습니까?이 스크립트를 사용하면 한 번에 모든 스크립트를 삭제할 수 있습니까?
다음 명령을 사용하여 PREFIX
원격 서버 에서 접두사가있는 모든 분기를 제거하십시오 .
git branch -r | awk -F/ '/\/PREFIX/{print $2}' | xargs -I {} git push origin :{}
먼저 드라 이런을 수행하여 제거하려는 브랜치인지 확인하십시오.
git branch -r | awk -F/ '/\/PREFIX/{print $2}'
더 간단한 접근 방식을 원한다면 3 개 또는 4 개의 분기를 삭제하십시오.
git push origin --delete <branch1> <branch2> <branch3>
중요 : Git v1.7.0 이상 에서만 작동합니다 .
훌륭하고 우아한 솔루션 을 제공 한 Neevek 에게 감사합니다 !
그러나 awk
필드 구분 기호 /
( -F
옵션)로 인해 분기 이름에 슬래시 (Git Flow를 사용하고 있음)에 문제가 있습니다.
따라서 내 솔루션은 Neevek을 기반으로 하지만 지점 이름을로 올바르게 구문 분석합니다 /
. 이 경우 리모컨이 전화했다고 가정합니다 origin
. 이름이 PATTERN
다음 과 같은 원격 브랜치를 삭제하는 명령 :
git branch -r | awk -Forigin/ '/\/PATTERN/ {print $2}' | xargs -I {} git push origin :{}
삭제하려는 항목을 확인하는 것을 잊지 마십시오.
git branch -r | awk -Forigin/ '/\/PATTERN/ {print $2}'
유용한 팁 : 지점 이름 ( origin/
접두사 없이 )이 텍스트 파일 (한 줄에 한 지점 이름)에 저장된 경우 다음을 실행하십시오.
cat your_file.txt | xargs -I {} git push origin :{}
grep과 동일 git branch -r | grep -Eo 'PREFIX/.*' | xargs -i git push origin :{}
합니다.
branch -r
보여줍니다 origin/prefix/branchname
. 그래서 걸릴 것 prefix/branchname
입니다.
Neevek의 솔루션은 훌륭하지만 더 나을 수 있습니다. 제안 된 솔루션은 분기당 한 번 'git push'를 호출하므로 분기당 추가 네트워크 왕복을 삭제할 수 있습니다. 어쨌든 awk를 사용하고 있기 때문에 왜 ':'접두어를 사용하지 않으면 xargs는 'git push'를 정확히 한 번 호출하고 모든 분기를 한 번에 삭제할 수 있습니다.
삭제 될 분기를 나열하기위한 드라 이런
git branch -r | awk -F/ '/\/PREFIX/{print ":" $2}'
실제로 삭제를 푸시하는 최종 솔루션 :
git branch -r | awk -F/ '/\/PREFIX/{print ":" $2}' | xargs git push origin
리소스 https://coderwall.com/p/eis0ba
1 - List all your remote branches:
$ git branch -r
2 - Filter the branches by some regular expression. In this case I'm interested in deleting any branch with the 'feature-' prefix:
$ git branch -r | awk -F/ '/\/feature-/{print $2}'
3 - Pipe the last command to git push to delete them:
# **Edit** - Removed extra colon, which is not needed
$ git branch -r | awk -F/ '/\/feature-/{print $2}' | xargs -I {} git push origin {}
4 - Grab a beer.
5 - Remove any local reference to those branches:
$ git remote prune origin
이것은 중복 답변 일 수 있지만 아래에서 테스트되어 완벽하게 작동했습니다.
- 로컬 지점을 강제로 삭제
자식 분기 -D 분기 이름
- 원격 지사 삭제
자식 푸시 원점-branch-name 삭제
- 로컬 지점을 두 개 이상 삭제
자식 분기 -D branch-name1 branch-name2
- 하나 이상의 원격 지사 삭제
자식 푸시 원점-branch-name1 삭제 branch-name2
- Delete local branch with prefix. For example, feature/*
git branch -D $(git branch --list 'feature/*')
git branch -D backticks $(git branch --list 'feature/*' backticks)
- List remote branch with prefix.
git branch -r | grep -Eo 'feature/.*'
- Delete remote branch with prefix
git branch -r | grep -Eo 'feature/.*' | xargs -I {} git push origin :{}
Thanks to Steve and Neevek, I found a solution that worked pretty well for me I figured worth sharing:
Steve's solution worked for me with one minor adjustment. My remotes were named origin/feature/some-feature-name
so I trimmed your awk
:
git branch -r | awk -Forigin/ '/\/feature/ {print $2 $3}' | xargs -I {} git push origin :{}
It's now doing a nice little delete flow:
To github.com:project/project-name.git
- [deleted] feature/search-min-chars
To github.com:project/project-name.git
- [deleted] feature/search-placeholder
To github.com:project/project-name.git
- [deleted] feature/server-error-message
To github.com:project/project-name.git
- [deleted] feature/six-point-asterisk
Was wondering if anyone had any ideas for a more elegant solution, though, that might output something like this (my CLI scripting is pretty poor, so it'd take me awhile to figure this out):
git push origin :feature/search-min-chars :feature/search-placeholder :feature/server-error-message :feature/six-point-asterisk
This would result in a nice single output with one network request:
To github.com:project/project-name.git
- [deleted] feature/search-min-chars
- [deleted] feature/search-placeholder
- [deleted] feature/server-error-message
- [deleted] feature/six-point-asterisk
Thanks to Neevek. This worked well after reconfiguring it for my purpose:
git branch -r | awk -Forigin/ '/\/PATTERN/ {print $2 "/" $3}' | xargs -I {} git push origin :{}
I also needed take the folder structure into account. My feature-branches are in a folder structure like origin/feature/PREFIX-FEATURENUMBER. So i had to build up my pattern from $2=folder + $3= branchname.
Everyone is using awk
, not sure why. I feel like that's more complex. Here is what I use to delete all remote branches on my fork
remote:
$ git branch -r --list 'fork/*' | sed 's/fork\///' | xargs git push --delete fork
Throw in a grep
between the xargs
and sed
if you need to filter the list down to only a subset of remote branches.
I realize this is for git command, but if you looking for an alternate solution to do the similar or same result:
You can do it from here (Git Remove Remote Branches):
Then select the branches you want:
Make sure you have the permissions to remove the remote branches.
Github also has a nice UI and mechanism for quickly deleting branches, that's if you'd rather use a UI
I tried to delete all origin/release/r1-1* remote branches, hence following command line worked nicely.
git branch -r | awk -Forigin/ '/\/*r1-1/ {print $2}' | xargs -I {} git push origin :{}
I was not able to use awk because we are using a slash structure for our branches' name.
git branch -r | grep "origin/users/YOURNAME" | sed -r 's/^.{9}//'| xargs -i sh -c 'git push origin --delete {}'
This get all remote branch, get only the one for a single user, remote the "origin/" string and execute a delete on each of them.
Warning: This will delete all remote branches. Use with caution.
I think my way deleting remote branches is the best.
Warning: This will delete all remote branches.
git branch -r | grep -v master | sed 's/origin\//:/'| xargs git push
참고URL : https://stackoverflow.com/questions/10555136/delete-multiple-remote-branches-in-git
'program tip' 카테고리의 다른 글
iOS 5 모범 사례 (릴리스 / 보존?) (0) | 2020.08.03 |
---|---|
바이트 배열을 비트 맵으로 변환하는 방법 (0) | 2020.08.03 |
Android-애플리케이션 이름을 얻는 방법 (0) | 2020.08.03 |
테이블의 한 필드 만 기준으로 Linq에서 구별 (0) | 2020.08.03 |
Object.freeze () 대 const (0) | 2020.08.03 |