고스트 인 더 셸 스크립트

R-Blogger · 블로그·해설 · 2026-05-29

R-Blogger블로그·해설한국어2026-05-29

고스트 인 더 셸 스크립트

Ghost in the Shell Script저는 거의 20년 동안 Unix와 Linux 시스템을 사용해 왔습니다. 한때 Windows 노트북을 사용하게 되었을 때는 길을 잃은 듯한 느낌이 들어 바로 Windows Subsystem for Linux를 설치했습니다. 그러면서도 제가 정기적으로 알고 사용하는 명령은 의외로 짧았습니다: cd, ls, rm, pwd, mkdir, source, node, npm그리고 물론 git입니다. 그래도 저는 아직 git을 “정말 안다”는 느낌이 들지는 않습니다.스티브 크루그의 훌륭한 책 Don’t Make Me Think Revisited에서는 기술을 마주했을 때 대부분의 사람들이 설명서를 읽는 대신 바로 진행하면서 대강의 이야기를 만들어낸다고 설명합니다. 이 책은 웹·모바일 사용성을 다루지만, 그 핵심은 모든 기술 영역에 적용됩니다. 저는 Unix와 함께 “대충 해 나가고” 있었던 것이 확실합니다. 어떤 것이 Unix 명령인지 쉘의 일부인지 물어보면 “글쎄요, 저도 잘 모르겠어요!” 라고 대답할 가능성이 높습니다.그전까지는 StackOverflow가 저의 버팀목이었습니다. 답변에서 자주 등장하는 find명령이 매우 유용하고 다재다능하다는 것은 알고 있었지만, 어떻게 사용하는지는 찾아보지 않으면 기억이 나지 않았습니다. 이제는 다양한 대형 언어 모델, 즉 멀티모달 AI 어시스턴트(Claude, ChatGPT 등)와 에이전트(Claude Code, Codex) 등을 활용할 수 있습니다. 저는 AI에 대해 중립적인 입장을 가지고 있으며 장점과 우려를 동시에 보고 있습니다. 그래서 약간의 회의감과 함께 Claude를 이용해 쉘 함수를 작성해 보았습니다. “제가” 작성했다고 말했지만, 실제로는 Claude에게 코드를 작성·수정하도록 요청하고 그 결과를 검토한 것입니다. 이는 제가 Claude를 평가하려는 것이 아니라, 작성된 코드를 이해하고자 하는 노력의 일환입니다.Task One: 흔히 저지르는 git 실수 고치기가장 자주 하는 실수는 git커밋을 잘못된 브랜치(주로 main)에 남기는 것입니다. 이를 복구하는 방법은 새 기능 브랜치를 만들고, 인터랙티브 리베이스로 main에서 해당 커밋을 제거한 뒤, 새 브랜치로 전환하는 것입니다. 절차는 몇 단계에 불과하지만 여전히 번거롭습니다. Claude에게 물어보았습니다.Tim: If you git [commit] to a wrong branch, is there a quick way to move the change to a new branch and remove it from the last commit from the current branch?Claude: Yes — assuming you haven’t pushed yet: # Create and switch to the correct branch from current state git switch -c correct-branch # Go back to the wrong branch and undo the commit (keeps changes staged) git switch wrong-branch git reset --soft HEAD~1 # Discard the changes git restore --staged . git restore . Or if you want to keep it even simpler — if the commit is only on the wrong branch and not pushed: git switch -c correct-branch git switch wrong-branch git reset --hard HEAD~1 The switch -c creates the new branch pointing at the same commit, so your work is preserved there. Then you just strip it off the wrong branch with reset –hard.여기서 두 가지 문제가 나타났습니다. Claude의 제안은 제가 원했던 최종 단계인 “새로운 올바른 브랜치로 돌아가기”를 포함하지 않았습니다. 이는 전적으로 제 실수이며, 저는 그 부분을 물어보지 않았기 때문입니다. 간단한 작업이라도 Claude의 응답은 다소 장황할 수 있습니다. 실제 문제는 Claude나 다른 에이전트를 사용하는 것이 아니라, 대화를 정확히 전달하면서도 적당한 길이의 블로그 글을 쓰는 것이 어려운 점입니다. 따라서 아래 내용은 원문을 요약한 형태이며, 여러분의 이해를 돕기 위한 것입니다.Tim: Can I use git switch - instead?Claude: Yes, and it’s cleaner. git switch - saves you typing the wrong branch name out explicitly.Tim: Seems like the sort of thing I should make into a Bash function.Claude: Agreed. Something like this (with an added safety check): git-move-last() { if [ -z "$1" ]; then echo "Usage: git-move-last " return 1 fi git switch -c "$1" git switch - git reset --hard HEAD~1 }Tim: I’ve gone for git-behead. If I wanted to move to the new branch at the end I just add another git switch -?Claude: Ha 🪓. Exactly: git-behead() { if [ -z "$1" ]; then echo "Usage: git-behead " return 1 fi git switch -c "$1" git switch - git reset --hard HEAD~1 git switch - }Tim: Ok, one more idea. Suppose I haven’t been looking what I’m doing and I want to remove more than just the last commit to a new branch. Can we recreate the above but with an optional commit count that defaults to 1?Claude: git-behead() { if [ -z "$1" ]; then echo "Usage: git-behead [commit-count]" return 1 fi count=${1:-1} git switch -c "temp-branch" git switch - git reset --hard HEAD~$count git switch - }
원문 URL
전체 글은 원문 페이지에서 이어서 읽을 수 있습니다.
원문에서 전체 글 읽기
작성자
The Jumping Rivers Blog
출처
R-Blogger
플랫폼
R-Blogger
분류
블로그·해설
언어
한국어
발행일
2026-05-29