CINXE.COM
Git - Stashing과 Cleaning
<!DOCTYPE html> <html lang="ko"> <head> <meta charset='utf-8'> <meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible'> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Git - Stashing과 Cleaning</title> <link href="/favicon.ico" rel='shortcut icon' type='image/x-icon'> <link rel="stylesheet" href="/application.min.css"> <script src="/js/modernizr.js"></script> <script src="/js/modernize.js"></script> </head> <body id="documentation"> <div class="inner"> <header> <a href="/"><img src="/images/logo@2x.png" width="110" height="46" alt="Git" /></a> <span id="tagline"></span> <script type="text/javascript"> const taglines = [ "fast-version-control", "everything-is-local", "distributed-even-if-your-workflow-isnt", "local-branching-on-the-cheap", "distributed-is-the-new-centralized" ]; var tagline = taglines[Math.floor(Math.random() * taglines.length)]; document.getElementById('tagline').innerHTML = '--' + tagline; </script> <form id="search" action="/search/results"> <input id="search-text" name="search" placeholder="Type / to search entire site…" autocomplete="off" type="text" /> </form> <div id="search-results"></div> </header> </div> <div class="inner"> <div id="content-wrapper"> <div tabindex="1" class="sidebar-btn"></div> <aside class="sidebar" id="sidebar"> <nav> <ul> <li> <a href="/about">About</a> <ul> </ul> </li> <li> <a href="/doc" class="active">Documentation</a> <ul class="expanded"> <li> <a href="/docs">Reference</a> </li> <li> <a href="/book" class="active">Book</a> </li> <li> <a href="/videos">Videos</a> </li> <li> <a href="/doc/ext">External Links</a> </li> </ul> </li> <li> <a href="/downloads">Downloads</a> <ul > <li> <a href="/downloads/guis">GUI Clients</a> </li> <li> <a href="/downloads/logos">Logos</a> </li> </ul> </li> <li> <a href="/community">Community</a> </li> </ul> <hr class="sidebar"> <p> This book is available in <a href="/book/en/v2/Git-Tools-Stashing-and-Cleaning">English</a>. </p> <p> Full translation available in <table> <tr><td><a href="/book/az/v2/Git-Al%c9%99tl%c9%99ri-Stashing-v%c9%99-T%c9%99mizl%c9%99m%c9%99">azərbaycan dili</a>,</td></tr> <tr><td><a href="/book/bg/v2/Git-%d0%b8-%d0%b4%d1%80%d1%83%d0%b3%d0%b8-%d1%81%d0%b8%d1%81%d1%82%d0%b5%d0%bc%d0%b8-%d0%9e%d0%b1%d0%be%d0%b1%d1%89%d0%b5%d0%bd%d0%b8%d0%b5">български език</a>,</td></tr> <tr><td><a href="/book/de/v2/Git-Tools-Stashen-und-Bereinigen">Deutsch</a>,</td></tr> <tr><td><a href="/book/es/v2/Herramientas-de-Git-Guardado-r%c3%a1pido-y-Limpieza">Español</a>,</td></tr> <tr><td><a href="/book/fr/v2/Utilitaires-Git-Remisage-et-nettoyage">Français</a>,</td></tr> <tr><td><a href="/book/gr">Ελληνικά</a>,</td></tr> <tr><td><a href="/book/ja/v2/Git-%e3%81%ae%e3%81%95%e3%81%be%e3%81%96%e3%81%be%e3%81%aa%e3%83%84%e3%83%bc%e3%83%ab-%e4%bd%9c%e6%a5%ad%e3%81%ae%e9%9a%a0%e3%81%97%e3%81%8b%e3%81%9f%e3%81%a8%e6%b6%88%e3%81%97%e3%81%8b%e3%81%9f">日本語</a>,</td></tr> <tr><td><a href="/book/ko/v2/Git-%eb%8f%84%ea%b5%ac-Stashing%ea%b3%bc-Cleaning">한국어</a>,</td></tr> <tr><td><a href="/book/nl/v2/Git-Tools-Stashen-en-opschonen">Nederlands</a>,</td></tr> <tr><td><a href="/book/ru/v2/%d0%98%d0%bd%d1%81%d1%82%d1%80%d1%83%d0%bc%d0%b5%d0%bd%d1%82%d1%8b-Git-%d0%9f%d1%80%d0%b8%d0%bf%d1%80%d1%8f%d1%82%d1%8b%d0%b2%d0%b0%d0%bd%d0%b8%d0%b5-%d0%b8-%d0%be%d1%87%d0%b8%d1%81%d1%82%d0%ba%d0%b0">Русский</a>,</td></tr> <tr><td><a href="/book/sl/v2/Orodja-Git-Shranjevanje-na-varno-angl-stashing-in-%c4%8di%c5%a1%c4%8denje">Slovenščina</a>,</td></tr> <tr><td><a href="/book/tl/v2/Mga-Git-na-Kasangkapan-Pag-stash-at-Paglilinis">Tagalog</a>,</td></tr> <tr><td><a href="/book/uk/v2/%d0%86%d0%bd%d1%81%d1%82%d1%80%d1%83%d0%bc%d0%b5%d0%bd%d1%82%d0%b8-Git-%d0%a5%d0%be%d0%b2%d0%b0%d0%bd%d0%bd%d1%8f-%d1%82%d0%b0-%d1%87%d0%b8%d1%89%d0%b5%d0%bd%d0%bd%d1%8f">Українська</a></td></tr> <tr><td><a href="/book/zh/v2/Git-%e5%b7%a5%e5%85%b7-%e8%b4%ae%e8%97%8f%e4%b8%8e%e6%b8%85%e7%90%86">简体中文</a>,</td></tr> </table> </p> <p> Partial translations available in <table> <tr><td><a href="/book/cs/v2/Git-Tools-Stashing-and-Cleaning">Čeština</a>,</td></tr> <tr><td><a href="/book/mk/v2/Git-%d0%90%d0%bb%d0%b0%d1%82%d0%ba%d0%b8-Stashing-and-Cleaning">Македонски</a>,</td></tr> <tr><td><a href="/book/pl/v2/Narz%c4%99dzia-Gita-Schowek-i-czyszczenie">Polski</a>,</td></tr> <tr><td><a href="/book/sr/v2/%d0%93%d0%b8%d1%82-%d0%b0%d0%bb%d0%b0%d1%82%d0%b8-%d0%a1%d0%ba%d1%80%d0%b8%d0%b2%d0%b0%d1%9a%d0%b5-%d0%b8-%d1%87%d0%b8%d1%88%d1%9b%d0%b5%d1%9a%d0%b5">Српски</a>,</td></tr> <tr><td><a href="/book/uz/v2/Git-Tools-Stashing-and-Cleaning">Ўзбекча</a>,</td></tr> <tr><td><a href="/book/zh-tw/v2/Git-%e5%b7%a5%e5%85%b7-Stashing-and-Cleaning">繁體中文</a>,</td></tr> </table> </p> <p> Translations started for <table> <tr><td><a href="/book/be/v2/Git-Tools-Stashing-and-Cleaning">Беларуская</a>,</td></tr> <tr><td><a href="/book/fa/v2/Git-Tools-Stashing-and-Cleaning" dir="rtl">فارسی</a>,</td></tr> <tr><td><a href="/book/id/v2/Git-Tools-Stashing-and-Cleaning">Indonesian</a>,</td></tr> <tr><td><a href="/book/it/v2/Git-Tools-Stashing-and-Cleaning">Italiano</a>,</td></tr> <tr><td><a href="/book/ms/v2/Git-Tools-Stashing-and-Cleaning">Bahasa Melayu</a>,</td></tr> <tr><td><a href="/book/pt-br/v2/Git-Tools-Stashing-and-Cleaning">Português (Brasil)</a>,</td></tr> <tr><td><a href="/book/pt-pt/v2/Ferramentas-do-Git-Stashing-and-Cleaning">Português (Portugal)</a>,</td></tr> <tr><td><a href="/book/sv/v2/Git-Tools-Stashing-and-Cleaning">Svenska</a>,</td></tr> <tr><td><a href="/book/tr/v2/Git-Ara%c3%a7lar%c4%b1-Saklama-ve-Silme">Türkçe</a>.</td></tr> </table> </p> <hr class="sidebar"/> <p> The source of this book is <a href="https://github.com/progit/progit2-ko">hosted on GitHub.</a></br> Patches, suggestions and comments are welcome. </p> </nav> </aside> <div id="content"> <div id="book-chapters"> <a class="dropdown-trigger" id="book-chapters-trigger" data-panel-id="chapters-dropdown" href="#">Chapters ▾</a> <div class='dropdown-panel' id='chapters-dropdown'> <div class='three-column'> <div class="column-left"> <ol class='book-toc'> <li class='chapter'> <h2>1. <a href="/book/ko/v2/%ec%8b%9c%ec%9e%91%ed%95%98%ea%b8%b0-%eb%b2%84%ec%a0%84-%ea%b4%80%eb%a6%ac%eb%9e%80%3F">시작하기</a></h2> <ol> <li> 1.1 <a href="/book/ko/v2/%ec%8b%9c%ec%9e%91%ed%95%98%ea%b8%b0-%eb%b2%84%ec%a0%84-%ea%b4%80%eb%a6%ac%eb%9e%80%3F">버전 관리란?</a> </li> <li> 1.2 <a href="/book/ko/v2/%ec%8b%9c%ec%9e%91%ed%95%98%ea%b8%b0-%ec%a7%a7%ea%b2%8c-%eb%b3%b4%eb%8a%94-Git%ec%9d%98-%ec%97%ad%ec%82%ac">짧게 보는 Git의 역사</a> </li> <li> 1.3 <a href="/book/ko/v2/%ec%8b%9c%ec%9e%91%ed%95%98%ea%b8%b0-Git-%ea%b8%b0%ec%b4%88">Git 기초</a> </li> <li> 1.4 <a href="/book/ko/v2/%ec%8b%9c%ec%9e%91%ed%95%98%ea%b8%b0-CLI">CLI</a> </li> <li> 1.5 <a href="/book/ko/v2/%ec%8b%9c%ec%9e%91%ed%95%98%ea%b8%b0-Git-%ec%84%a4%ec%b9%98">Git 설치</a> </li> <li> 1.6 <a href="/book/ko/v2/%ec%8b%9c%ec%9e%91%ed%95%98%ea%b8%b0-Git-%ec%b5%9c%ec%b4%88-%ec%84%a4%ec%a0%95">Git 최초 설정</a> </li> <li> 1.7 <a href="/book/ko/v2/%ec%8b%9c%ec%9e%91%ed%95%98%ea%b8%b0-%eb%8f%84%ec%9b%80%eb%a7%90-%eb%b3%b4%ea%b8%b0">도움말 보기</a> </li> <li> 1.8 <a href="/book/ko/v2/%ec%8b%9c%ec%9e%91%ed%95%98%ea%b8%b0-%ec%9a%94%ec%95%bd">요약</a> </li> </ol> </li> <li class='chapter'> <h2>2. <a href="/book/ko/v2/Git%ec%9d%98-%ea%b8%b0%ec%b4%88-Git-%ec%a0%80%ec%9e%a5%ec%86%8c-%eb%a7%8c%eb%93%a4%ea%b8%b0">Git의 기초</a></h2> <ol> <li> 2.1 <a href="/book/ko/v2/Git%ec%9d%98-%ea%b8%b0%ec%b4%88-Git-%ec%a0%80%ec%9e%a5%ec%86%8c-%eb%a7%8c%eb%93%a4%ea%b8%b0">Git 저장소 만들기</a> </li> <li> 2.2 <a href="/book/ko/v2/Git%ec%9d%98-%ea%b8%b0%ec%b4%88-%ec%88%98%ec%a0%95%ed%95%98%ea%b3%a0-%ec%a0%80%ec%9e%a5%ec%86%8c%ec%97%90-%ec%a0%80%ec%9e%a5%ed%95%98%ea%b8%b0">수정하고 저장소에 저장하기</a> </li> <li> 2.3 <a href="/book/ko/v2/Git%ec%9d%98-%ea%b8%b0%ec%b4%88-%ec%bb%a4%eb%b0%8b-%ed%9e%88%ec%8a%a4%ed%86%a0%eb%a6%ac-%ec%a1%b0%ed%9a%8c%ed%95%98%ea%b8%b0">커밋 히스토리 조회하기</a> </li> <li> 2.4 <a href="/book/ko/v2/Git%ec%9d%98-%ea%b8%b0%ec%b4%88-%eb%90%98%eb%8f%8c%eb%a6%ac%ea%b8%b0">되돌리기</a> </li> <li> 2.5 <a href="/book/ko/v2/Git%ec%9d%98-%ea%b8%b0%ec%b4%88-%eb%a6%ac%eb%aa%a8%ed%8a%b8-%ec%a0%80%ec%9e%a5%ec%86%8c">리모트 저장소</a> </li> <li> 2.6 <a href="/book/ko/v2/Git%ec%9d%98-%ea%b8%b0%ec%b4%88-%ed%83%9c%ea%b7%b8">태그</a> </li> <li> 2.7 <a href="/book/ko/v2/Git%ec%9d%98-%ea%b8%b0%ec%b4%88-Git-Alias">Git Alias</a> </li> <li> 2.8 <a href="/book/ko/v2/Git%ec%9d%98-%ea%b8%b0%ec%b4%88-%ec%9a%94%ec%95%bd">요약</a> </li> </ol> </li> <li class='chapter'> <h2>3. <a href="/book/ko/v2/Git-%eb%b8%8c%eb%9e%9c%ec%b9%98-%eb%b8%8c%eb%9e%9c%ec%b9%98%eb%9e%80-%eb%ac%b4%ec%97%87%ec%9d%b8%ea%b0%80">Git 브랜치</a></h2> <ol> <li> 3.1 <a href="/book/ko/v2/Git-%eb%b8%8c%eb%9e%9c%ec%b9%98-%eb%b8%8c%eb%9e%9c%ec%b9%98%eb%9e%80-%eb%ac%b4%ec%97%87%ec%9d%b8%ea%b0%80">브랜치란 무엇인가</a> </li> <li> 3.2 <a href="/book/ko/v2/Git-%eb%b8%8c%eb%9e%9c%ec%b9%98-%eb%b8%8c%eb%9e%9c%ec%b9%98%ec%99%80-Merge-%ec%9d%98-%ea%b8%b0%ec%b4%88">브랜치와 Merge 의 기초</a> </li> <li> 3.3 <a href="/book/ko/v2/Git-%eb%b8%8c%eb%9e%9c%ec%b9%98-%eb%b8%8c%eb%9e%9c%ec%b9%98-%ea%b4%80%eb%a6%ac">브랜치 관리</a> </li> <li> 3.4 <a href="/book/ko/v2/Git-%eb%b8%8c%eb%9e%9c%ec%b9%98-%eb%b8%8c%eb%9e%9c%ec%b9%98-%ec%9b%8c%ed%81%ac%ed%94%8c%eb%a1%9c">브랜치 워크플로</a> </li> <li> 3.5 <a href="/book/ko/v2/Git-%eb%b8%8c%eb%9e%9c%ec%b9%98-%eb%a6%ac%eb%aa%a8%ed%8a%b8-%eb%b8%8c%eb%9e%9c%ec%b9%98">리모트 브랜치</a> </li> <li> 3.6 <a href="/book/ko/v2/Git-%eb%b8%8c%eb%9e%9c%ec%b9%98-Rebase-%ed%95%98%ea%b8%b0">Rebase 하기</a> </li> <li> 3.7 <a href="/book/ko/v2/Git-%eb%b8%8c%eb%9e%9c%ec%b9%98-%ec%9a%94%ec%95%bd">요약</a> </li> </ol> </li> <li class='chapter'> <h2>4. <a href="/book/ko/v2/Git-%ec%84%9c%eb%b2%84-%ed%94%84%eb%a1%9c%ed%86%a0%ec%bd%9c">Git 서버</a></h2> <ol> <li> 4.1 <a href="/book/ko/v2/Git-%ec%84%9c%eb%b2%84-%ed%94%84%eb%a1%9c%ed%86%a0%ec%bd%9c">프로토콜</a> </li> <li> 4.2 <a href="/book/ko/v2/Git-%ec%84%9c%eb%b2%84-%ec%84%9c%eb%b2%84%ec%97%90-Git-%ec%84%a4%ec%b9%98%ed%95%98%ea%b8%b0">서버에 Git 설치하기</a> </li> <li> 4.3 <a href="/book/ko/v2/Git-%ec%84%9c%eb%b2%84-SSH-%ea%b3%b5%ea%b0%9c%ed%82%a4-%eb%a7%8c%eb%93%a4%ea%b8%b0">SSH 공개키 만들기</a> </li> <li> 4.4 <a href="/book/ko/v2/Git-%ec%84%9c%eb%b2%84-%ec%84%9c%eb%b2%84-%ec%84%a4%ec%a0%95%ed%95%98%ea%b8%b0">서버 설정하기</a> </li> <li> 4.5 <a href="/book/ko/v2/Git-%ec%84%9c%eb%b2%84-Git-%eb%8d%b0%eb%aa%ac">Git 데몬</a> </li> <li> 4.6 <a href="/book/ko/v2/Git-%ec%84%9c%eb%b2%84-%ec%8a%a4%eb%a7%88%ed%8a%b8-HTTP">스마트 HTTP</a> </li> <li> 4.7 <a href="/book/ko/v2/Git-%ec%84%9c%eb%b2%84-GitWeb">GitWeb</a> </li> <li> 4.8 <a href="/book/ko/v2/Git-%ec%84%9c%eb%b2%84-GitLab">GitLab</a> </li> <li> 4.9 <a href="/book/ko/v2/Git-%ec%84%9c%eb%b2%84-%eb%98%90-%eb%8b%a4%eb%a5%b8-%ec%84%a0%ed%83%9d%ec%a7%80,-%ed%98%b8%ec%8a%a4%ed%8c%85">또 다른 선택지, 호스팅</a> </li> <li> 4.10 <a href="/book/ko/v2/Git-%ec%84%9c%eb%b2%84-%ec%9a%94%ec%95%bd">요약</a> </li> </ol> </li> <li class='chapter'> <h2>5. <a href="/book/ko/v2/%eb%b6%84%ec%82%b0-%ed%99%98%ea%b2%bd%ec%97%90%ec%84%9c%ec%9d%98-Git-%eb%b6%84%ec%82%b0-%ed%99%98%ea%b2%bd%ec%97%90%ec%84%9c%ec%9d%98-%ec%9b%8c%ed%81%ac%ed%94%8c%eb%a1%9c">분산 환경에서의 Git</a></h2> <ol> <li> 5.1 <a href="/book/ko/v2/%eb%b6%84%ec%82%b0-%ed%99%98%ea%b2%bd%ec%97%90%ec%84%9c%ec%9d%98-Git-%eb%b6%84%ec%82%b0-%ed%99%98%ea%b2%bd%ec%97%90%ec%84%9c%ec%9d%98-%ec%9b%8c%ed%81%ac%ed%94%8c%eb%a1%9c">분산 환경에서의 워크플로</a> </li> <li> 5.2 <a href="/book/ko/v2/%eb%b6%84%ec%82%b0-%ed%99%98%ea%b2%bd%ec%97%90%ec%84%9c%ec%9d%98-Git-%ed%94%84%eb%a1%9c%ec%a0%9d%ed%8a%b8%ec%97%90-%ea%b8%b0%ec%97%ac%ed%95%98%ea%b8%b0">프로젝트에 기여하기</a> </li> <li> 5.3 <a href="/book/ko/v2/%eb%b6%84%ec%82%b0-%ed%99%98%ea%b2%bd%ec%97%90%ec%84%9c%ec%9d%98-Git-%ed%94%84%eb%a1%9c%ec%a0%9d%ed%8a%b8-%ea%b4%80%eb%a6%ac%ed%95%98%ea%b8%b0">프로젝트 관리하기</a> </li> <li> 5.4 <a href="/book/ko/v2/%eb%b6%84%ec%82%b0-%ed%99%98%ea%b2%bd%ec%97%90%ec%84%9c%ec%9d%98-Git-%ec%9a%94%ec%95%bd">요약</a> </li> </ol> </li> </ol> </div> <div class='column-middle'> <ol class='book-toc'> <li class='chapter'> <h2>6. <a href="/book/ko/v2/GitHub-%ea%b3%84%ec%a0%95-%eb%a7%8c%eb%93%a4%ea%b3%a0-%ec%84%a4%ec%a0%95%ed%95%98%ea%b8%b0">GitHub</a></h2> <ol> <li> 6.1 <a href="/book/ko/v2/GitHub-%ea%b3%84%ec%a0%95-%eb%a7%8c%eb%93%a4%ea%b3%a0-%ec%84%a4%ec%a0%95%ed%95%98%ea%b8%b0">계정 만들고 설정하기</a> </li> <li> 6.2 <a href="/book/ko/v2/GitHub-GitHub-%ed%94%84%eb%a1%9c%ec%a0%9d%ed%8a%b8%ec%97%90-%ea%b8%b0%ec%97%ac%ed%95%98%ea%b8%b0">GitHub 프로젝트에 기여하기</a> </li> <li> 6.3 <a href="/book/ko/v2/GitHub-GitHub-%ed%94%84%eb%a1%9c%ec%a0%9d%ed%8a%b8-%ea%b4%80%eb%a6%ac%ed%95%98%ea%b8%b0">GitHub 프로젝트 관리하기</a> </li> <li> 6.4 <a href="/book/ko/v2/GitHub-Organization-%ea%b4%80%eb%a6%ac%ed%95%98%ea%b8%b0">Organization 관리하기</a> </li> <li> 6.5 <a href="/book/ko/v2/GitHub-GitHub-%ec%8a%a4%ed%81%ac%eb%a6%bd%ed%8c%85">GitHub 스크립팅</a> </li> <li> 6.6 <a href="/book/ko/v2/GitHub-%ec%9a%94%ec%95%bd">요약</a> </li> </ol> </li> <li class='chapter'> <h2>7. <a href="/book/ko/v2/Git-%eb%8f%84%ea%b5%ac-%eb%a6%ac%eb%b9%84%ec%a0%84-%ec%a1%b0%ed%9a%8c%ed%95%98%ea%b8%b0">Git 도구</a></h2> <ol> <li> 7.1 <a href="/book/ko/v2/Git-%eb%8f%84%ea%b5%ac-%eb%a6%ac%eb%b9%84%ec%a0%84-%ec%a1%b0%ed%9a%8c%ed%95%98%ea%b8%b0">리비전 조회하기</a> </li> <li> 7.2 <a href="/book/ko/v2/Git-%eb%8f%84%ea%b5%ac-%eb%8c%80%ed%99%94%ed%98%95-%eb%aa%85%eb%a0%b9">대화형 명령</a> </li> <li> 7.3 <a href="/book/ko/v2/Git-%eb%8f%84%ea%b5%ac-Stashing%ea%b3%bc-Cleaning" class="active">Stashing과 Cleaning</a> </li> <li> 7.4 <a href="/book/ko/v2/Git-%eb%8f%84%ea%b5%ac-%eb%82%b4-%ec%9e%91%ec%97%85%ec%97%90-%ec%84%9c%eb%aa%85%ed%95%98%ea%b8%b0">내 작업에 서명하기</a> </li> <li> 7.5 <a href="/book/ko/v2/Git-%eb%8f%84%ea%b5%ac-%ea%b2%80%ec%83%89">검색</a> </li> <li> 7.6 <a href="/book/ko/v2/Git-%eb%8f%84%ea%b5%ac-%ed%9e%88%ec%8a%a4%ed%86%a0%eb%a6%ac-%eb%8b%a8%ec%9e%a5%ed%95%98%ea%b8%b0">히스토리 단장하기</a> </li> <li> 7.7 <a href="/book/ko/v2/Git-%eb%8f%84%ea%b5%ac-Reset-%eb%aa%85%ed%99%95%ed%9e%88-%ec%95%8c%ea%b3%a0-%ea%b0%80%ea%b8%b0">Reset 명확히 알고 가기</a> </li> <li> 7.8 <a href="/book/ko/v2/Git-%eb%8f%84%ea%b5%ac-%ea%b3%a0%ea%b8%89-Merge">고급 Merge</a> </li> <li> 7.9 <a href="/book/ko/v2/Git-%eb%8f%84%ea%b5%ac-Rerere">Rerere</a> </li> <li> 7.10 <a href="/book/ko/v2/Git-%eb%8f%84%ea%b5%ac-Git%ec%9c%bc%eb%a1%9c-%eb%b2%84%ea%b7%b8-%ec%b0%be%ea%b8%b0">Git으로 버그 찾기</a> </li> <li> 7.11 <a href="/book/ko/v2/Git-%eb%8f%84%ea%b5%ac-%ec%84%9c%eb%b8%8c%eb%aa%a8%eb%93%88">서브모듈</a> </li> <li> 7.12 <a href="/book/ko/v2/Git-%eb%8f%84%ea%b5%ac-Bundle">Bundle</a> </li> <li> 7.13 <a href="/book/ko/v2/Git-%eb%8f%84%ea%b5%ac-Replace">Replace</a> </li> <li> 7.14 <a href="/book/ko/v2/Git-%eb%8f%84%ea%b5%ac-Credential-%ec%a0%80%ec%9e%a5%ec%86%8c">Credential 저장소</a> </li> <li> 7.15 <a href="/book/ko/v2/Git-%eb%8f%84%ea%b5%ac-%ec%9a%94%ec%95%bd">요약</a> </li> </ol> </li> <li class='chapter'> <h2>8. <a href="/book/ko/v2/Git%eb%a7%9e%ec%b6%a4-Git-%ec%84%a4%ec%a0%95%ed%95%98%ea%b8%b0">Git맞춤</a></h2> <ol> <li> 8.1 <a href="/book/ko/v2/Git%eb%a7%9e%ec%b6%a4-Git-%ec%84%a4%ec%a0%95%ed%95%98%ea%b8%b0">Git 설정하기</a> </li> <li> 8.2 <a href="/book/ko/v2/Git%eb%a7%9e%ec%b6%a4-Git-Attributes">Git Attributes</a> </li> <li> 8.3 <a href="/book/ko/v2/Git%eb%a7%9e%ec%b6%a4-Git-Hooks">Git Hooks</a> </li> <li> 8.4 <a href="/book/ko/v2/Git%eb%a7%9e%ec%b6%a4-%ec%a0%95%ec%b1%85-%ea%b5%ac%ed%98%84%ed%95%98%ea%b8%b0">정책 구현하기</a> </li> <li> 8.5 <a href="/book/ko/v2/Git%eb%a7%9e%ec%b6%a4-%ec%9a%94%ec%95%bd">요약</a> </li> </ol> </li> <li class='chapter'> <h2>9. <a href="/book/ko/v2/Git%ea%b3%bc-%ec%97%ac%ed%83%80-%eb%b2%84%ec%a0%84-%ea%b4%80%eb%a6%ac-%ec%8b%9c%ec%8a%a4%ed%85%9c-Git:-%eb%b2%94%ec%9a%a9-Client">Git과 여타 버전 관리 시스템</a></h2> <ol> <li> 9.1 <a href="/book/ko/v2/Git%ea%b3%bc-%ec%97%ac%ed%83%80-%eb%b2%84%ec%a0%84-%ea%b4%80%eb%a6%ac-%ec%8b%9c%ec%8a%a4%ed%85%9c-Git:-%eb%b2%94%ec%9a%a9-Client">Git: 범용 Client</a> </li> <li> 9.2 <a href="/book/ko/v2/Git%ea%b3%bc-%ec%97%ac%ed%83%80-%eb%b2%84%ec%a0%84-%ea%b4%80%eb%a6%ac-%ec%8b%9c%ec%8a%a4%ed%85%9c-Git%ec%9c%bc%eb%a1%9c-%ec%98%ae%ea%b8%b0%ea%b8%b0">Git으로 옮기기</a> </li> <li> 9.3 <a href="/book/ko/v2/Git%ea%b3%bc-%ec%97%ac%ed%83%80-%eb%b2%84%ec%a0%84-%ea%b4%80%eb%a6%ac-%ec%8b%9c%ec%8a%a4%ed%85%9c-%ec%9a%94%ec%95%bd">요약</a> </li> </ol> </li> <li class='chapter'> <h2>10. <a href="/book/ko/v2/Git%ec%9d%98-%eb%82%b4%eb%b6%80-Plumbing-%eb%aa%85%eb%a0%b9%ea%b3%bc-Porcelain-%eb%aa%85%eb%a0%b9">Git의 내부</a></h2> <ol> <li> 10.1 <a href="/book/ko/v2/Git%ec%9d%98-%eb%82%b4%eb%b6%80-Plumbing-%eb%aa%85%eb%a0%b9%ea%b3%bc-Porcelain-%eb%aa%85%eb%a0%b9">Plumbing 명령과 Porcelain 명령</a> </li> <li> 10.2 <a href="/book/ko/v2/Git%ec%9d%98-%eb%82%b4%eb%b6%80-Git-%ea%b0%9c%ec%b2%b4">Git 개체</a> </li> <li> 10.3 <a href="/book/ko/v2/Git%ec%9d%98-%eb%82%b4%eb%b6%80-Git-Refs">Git Refs</a> </li> <li> 10.4 <a href="/book/ko/v2/Git%ec%9d%98-%eb%82%b4%eb%b6%80-Packfile">Packfile</a> </li> <li> 10.5 <a href="/book/ko/v2/Git%ec%9d%98-%eb%82%b4%eb%b6%80-Refspec">Refspec</a> </li> <li> 10.6 <a href="/book/ko/v2/Git%ec%9d%98-%eb%82%b4%eb%b6%80-%eb%8d%b0%ec%9d%b4%ed%84%b0-%ec%a0%84%ec%86%a1-%ed%94%84%eb%a1%9c%ed%86%a0%ec%bd%9c">데이터 전송 프로토콜</a> </li> <li> 10.7 <a href="/book/ko/v2/Git%ec%9d%98-%eb%82%b4%eb%b6%80-%ec%9a%b4%ec%98%81-%eb%b0%8f-%eb%8d%b0%ec%9d%b4%ed%84%b0-%eb%b3%b5%ea%b5%ac">운영 및 데이터 복구</a> </li> <li> 10.8 <a href="/book/ko/v2/Git%ec%9d%98-%eb%82%b4%eb%b6%80-%ed%99%98%ea%b2%bd%eb%b3%80%ec%88%98">환경변수</a> </li> <li> 10.9 <a href="/book/ko/v2/Git%ec%9d%98-%eb%82%b4%eb%b6%80-%ec%9a%94%ec%95%bd">요약</a> </li> </ol> </li> </ol> </div> <div class='column-right'> <ol class='book-toc'> <li class='chapter'> <h2>A1. <a href="/book/ko/v2/%eb%b6%80%eb%a1%9d-A:-%eb%8b%a4%ec%96%91%ed%95%9c-%ed%99%98%ea%b2%bd%ec%97%90%ec%84%9c-Git-%ec%82%ac%ec%9a%a9%ed%95%98%ea%b8%b0-GUI">부록 A: 다양한 환경에서 Git 사용하기</a></h2> <ol> <li> A1.1 <a href="/book/ko/v2/%eb%b6%80%eb%a1%9d-A:-%eb%8b%a4%ec%96%91%ed%95%9c-%ed%99%98%ea%b2%bd%ec%97%90%ec%84%9c-Git-%ec%82%ac%ec%9a%a9%ed%95%98%ea%b8%b0-GUI">GUI</a> </li> <li> A1.2 <a href="/book/ko/v2/%eb%b6%80%eb%a1%9d-A:-%eb%8b%a4%ec%96%91%ed%95%9c-%ed%99%98%ea%b2%bd%ec%97%90%ec%84%9c-Git-%ec%82%ac%ec%9a%a9%ed%95%98%ea%b8%b0-Visual-Studio">Visual Studio</a> </li> <li> A1.3 <a href="/book/ko/v2/%eb%b6%80%eb%a1%9d-A:-%eb%8b%a4%ec%96%91%ed%95%9c-%ed%99%98%ea%b2%bd%ec%97%90%ec%84%9c-Git-%ec%82%ac%ec%9a%a9%ed%95%98%ea%b8%b0-Eclipse">Eclipse</a> </li> <li> A1.4 <a href="/book/ko/v2/%eb%b6%80%eb%a1%9d-A:-%eb%8b%a4%ec%96%91%ed%95%9c-%ed%99%98%ea%b2%bd%ec%97%90%ec%84%9c-Git-%ec%82%ac%ec%9a%a9%ed%95%98%ea%b8%b0-Bash">Bash</a> </li> <li> A1.5 <a href="/book/ko/v2/%eb%b6%80%eb%a1%9d-A:-%eb%8b%a4%ec%96%91%ed%95%9c-%ed%99%98%ea%b2%bd%ec%97%90%ec%84%9c-Git-%ec%82%ac%ec%9a%a9%ed%95%98%ea%b8%b0-Zsh">Zsh</a> </li> <li> A1.6 <a href="/book/ko/v2/%eb%b6%80%eb%a1%9d-A:-%eb%8b%a4%ec%96%91%ed%95%9c-%ed%99%98%ea%b2%bd%ec%97%90%ec%84%9c-Git-%ec%82%ac%ec%9a%a9%ed%95%98%ea%b8%b0-Git-in-Powershell">Git in Powershell</a> </li> <li> A1.7 <a href="/book/ko/v2/%eb%b6%80%eb%a1%9d-A:-%eb%8b%a4%ec%96%91%ed%95%9c-%ed%99%98%ea%b2%bd%ec%97%90%ec%84%9c-Git-%ec%82%ac%ec%9a%a9%ed%95%98%ea%b8%b0-%ec%9a%94%ec%95%bd">요약</a> </li> </ol> </li> <li class='chapter'> <h2>A2. <a href="/book/ko/v2/%eb%b6%80%eb%a1%9d-B:-%ec%95%a0%ed%94%8c%eb%a6%ac%ec%bc%80%ec%9d%b4%ec%85%98%ec%97%90-Git-%eb%84%a3%ea%b8%b0-Git-%eb%aa%85%eb%a0%b9%ec%96%b4">부록 B: 애플리케이션에 Git 넣기</a></h2> <ol> <li> A2.1 <a href="/book/ko/v2/%eb%b6%80%eb%a1%9d-B:-%ec%95%a0%ed%94%8c%eb%a6%ac%ec%bc%80%ec%9d%b4%ec%85%98%ec%97%90-Git-%eb%84%a3%ea%b8%b0-Git-%eb%aa%85%eb%a0%b9%ec%96%b4">Git 명령어</a> </li> <li> A2.2 <a href="/book/ko/v2/%eb%b6%80%eb%a1%9d-B:-%ec%95%a0%ed%94%8c%eb%a6%ac%ec%bc%80%ec%9d%b4%ec%85%98%ec%97%90-Git-%eb%84%a3%ea%b8%b0-Libgit2">Libgit2</a> </li> <li> A2.3 <a href="/book/ko/v2/%eb%b6%80%eb%a1%9d-B:-%ec%95%a0%ed%94%8c%eb%a6%ac%ec%bc%80%ec%9d%b4%ec%85%98%ec%97%90-Git-%eb%84%a3%ea%b8%b0-JGit">JGit</a> </li> <li> A2.4 <a href="/book/ko/v2/%eb%b6%80%eb%a1%9d-B:-%ec%95%a0%ed%94%8c%eb%a6%ac%ec%bc%80%ec%9d%b4%ec%85%98%ec%97%90-Git-%eb%84%a3%ea%b8%b0-go-git">go-git</a> </li> </ol> </li> <li class='chapter'> <h2>A3. <a href="/book/ko/v2/%eb%b6%80%eb%a1%9d-C:-Git-%eb%aa%85%eb%a0%b9%ec%96%b4-%ec%84%a4%ec%b9%98%ec%99%80-%ec%84%a4%ec%a0%95">부록 C: Git 명령어</a></h2> <ol> <li> A3.1 <a href="/book/ko/v2/%eb%b6%80%eb%a1%9d-C:-Git-%eb%aa%85%eb%a0%b9%ec%96%b4-%ec%84%a4%ec%b9%98%ec%99%80-%ec%84%a4%ec%a0%95">설치와 설정</a> </li> <li> A3.2 <a href="/book/ko/v2/%eb%b6%80%eb%a1%9d-C:-Git-%eb%aa%85%eb%a0%b9%ec%96%b4-%ed%94%84%eb%a1%9c%ec%a0%9d%ed%8a%b8-%ea%b0%80%ec%a0%b8%ec%98%a4%ea%b8%b0%ec%99%80-%ec%83%9d%ec%84%b1%ed%95%98%ea%b8%b0">프로젝트 가져오기와 생성하기</a> </li> <li> A3.3 <a href="/book/ko/v2/%eb%b6%80%eb%a1%9d-C:-Git-%eb%aa%85%eb%a0%b9%ec%96%b4-%ec%8a%a4%eb%83%85%ec%83%b7-%eb%8b%a4%eb%a3%a8%ea%b8%b0">스냅샷 다루기</a> </li> <li> A3.4 <a href="/book/ko/v2/%eb%b6%80%eb%a1%9d-C:-Git-%eb%aa%85%eb%a0%b9%ec%96%b4-Branch%ec%99%80-Merge">Branch와 Merge</a> </li> <li> A3.5 <a href="/book/ko/v2/%eb%b6%80%eb%a1%9d-C:-Git-%eb%aa%85%eb%a0%b9%ec%96%b4-%ea%b3%b5%ec%9c%a0%ed%95%98%ea%b3%a0-%ec%97%85%eb%8d%b0%ec%9d%b4%ed%8a%b8%ed%95%98%ea%b8%b0">공유하고 업데이트하기</a> </li> <li> A3.6 <a href="/book/ko/v2/%eb%b6%80%eb%a1%9d-C:-Git-%eb%aa%85%eb%a0%b9%ec%96%b4-%eb%b3%b4%ea%b8%b0%ec%99%80-%eb%b9%84%ea%b5%90">보기와 비교</a> </li> <li> A3.7 <a href="/book/ko/v2/%eb%b6%80%eb%a1%9d-C:-Git-%eb%aa%85%eb%a0%b9%ec%96%b4-Debugging">Debugging</a> </li> <li> A3.8 <a href="/book/ko/v2/%eb%b6%80%eb%a1%9d-C:-Git-%eb%aa%85%eb%a0%b9%ec%96%b4-Patch-%ed%95%98%ea%b8%b0">Patch 하기</a> </li> <li> A3.9 <a href="/book/ko/v2/%eb%b6%80%eb%a1%9d-C:-Git-%eb%aa%85%eb%a0%b9%ec%96%b4-Email">Email</a> </li> <li> A3.10 <a href="/book/ko/v2/%eb%b6%80%eb%a1%9d-C:-Git-%eb%aa%85%eb%a0%b9%ec%96%b4-%eb%8b%a4%eb%a5%b8-%eb%b2%84%ec%a0%84-%ea%b4%80%eb%a6%ac-%ec%8b%9c%ec%8a%a4%ed%85%9c">다른 버전 관리 시스템</a> </li> <li> A3.11 <a href="/book/ko/v2/%eb%b6%80%eb%a1%9d-C:-Git-%eb%aa%85%eb%a0%b9%ec%96%b4-%ea%b4%80%eb%a6%ac">관리</a> </li> <li> A3.12 <a href="/book/ko/v2/%eb%b6%80%eb%a1%9d-C:-Git-%eb%aa%85%eb%a0%b9%ec%96%b4-Plumbing-%eb%aa%85%eb%a0%b9%ec%96%b4">Plumbing 명령어</a> </li> </ol> </li> </ol> </div> </div> </div> <span class="light" id="edition"> 2nd Edition </span> </div> <div id="main" data-pagefind-filter="category:book" data-pagefind-meta="category:Book" data-pagefind-weight="0.05" data-pagefind-body class="book edition2"> <h1>7.3 Git 도구 - Stashing과 Cleaning</h1> <div> <h2 id="_git_stashing">Stashing과 Cleaning</h2> <div class="paragraph"> <p>당신이 어떤 프로젝트에서 한 부분을 담당하고 있다고 하자. 그리고 여기에서 뭔가 작업하던 일이 있고 다른 요청이 들어와서 잠시 브랜치를 변경해야 할 일이 생겼다고 치자. 그런데 이런 상황에서 아직 완료하지 않은 일을 커밋하는 것이 껄끄럽다는 것이 문제다. 커밋하지 않고 나중에 다시 돌아와서 작업을 다시 하고 싶을 것이다. 이 문제는 <code>git stash</code> 라는 명령으로 해결할 수 있다.</p> </div> <div class="paragraph"> <p>Stash 명령을 사용하면 워킹 디렉토리에서 수정한 파일들만 저장한다. Stash는 Modified이면서 Tracked 상태인 파일과 Staging Area에 있는 파일들을 보관해두는 장소다. 아직 끝내지 않은 수정사항을 스택에 잠시 저장했다가 나중에 다시 적용할 수 있다(브랜치가 달라져도 말이다).</p> </div> <div class="admonitionblock note"> <table> <tr> <td class="icon"> <div class="title">노트</div> </td> <td class="content"> <div class="title"> <code>git stash push</code> 로의 이동</div> <div class="paragraph"> <p>2017년 10월 말 Git 메일링 리스트에는 엄청난 논의가 있었습니다. 논의는 <code>git stash save</code> 명령을 은퇴시키고 <code>git stash push</code> 로 대체하는 내용에 대한 것이었습니다. <code>git stash push</code> 명령의 경우 <em>pathspec</em> 으로 선택하여 Stash하는 옵션이 추가되었는데 <code>git stash save</code> 명령이 지원하지 못하는 것이었습니다.</p> </div> <div class="paragraph"> <p><code>git stash save</code> 명령이 곧바로 삭제되는 것은 아니기에 아직 이 명령을 쓰는 것에 대해 걱정할 필요는 없지만 <code>git stash push</code> 명령으로 대체하는 것에 대해 생각해볼 필요가 있습니다.</p> </div> </td> </tr> </table> </div> <div class="sect3"> <h3 id="_하던_일을_stash_하기">하던 일을 Stash 하기</h3> <div class="paragraph"> <p>예제 프로젝트를 하나 살펴보자. 파일을 두 개 수정하고 그 중 하나는 Staging Area에 추가한다. 그리고 <code>git status</code> 명령을 실행하면 아래와 같은 결과를 볼 수 있다.</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git status Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: index.html Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: lib/simplegit.rb</code></pre> </div> </div> <div class="paragraph"> <p>이제 브랜치를 변경해 보자. 아직 작업 중인 파일은 커밋할 게 아니라서 모두 Stash 한다. <code>git stash</code> 나 <code>git stash save</code> 를 실행하면 스택에 새로운 Stash가 만들어진다.</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git stash Saved working directory and index state \ "WIP on master: 049d078 added the index file" HEAD is now at 049d078 added the index file (To restore them type "git stash apply")</code></pre> </div> </div> <div class="paragraph"> <p>대신 워킹 디렉토리는 깨끗해졌다.</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git status # On branch master nothing to commit, working directory clean</code></pre> </div> </div> <div class="paragraph"> <p>이제 아무 브랜치나 골라서 쉽게 바꿀 수 있다. 수정하던 것을 스택에 저장했다. 아래와 같이 <code>git stash list</code> 를 사용하여 저장한 Stash를 확인한다.</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git stash list stash@{0}: WIP on master: 049d078 added the index file stash@{1}: WIP on master: c264051 Revert "added file_size" stash@{2}: WIP on master: 21d80a5 added number to log</code></pre> </div> </div> <div class="paragraph"> <p>Stash 두 개는 원래 있었다. 그래서 현재 총 세 개의 Stash를 사용할 수 있다. 이제 <code>git stash apply</code> 를 사용하여 Stash를 다시 적용할 수 있다. <code>git stash</code> 명령을 실행하면 Stash를 다시 적용하는 방법도 알려줘서 편리하다. <code>git stash apply stash@{2}</code> 처럼 Stash 이름을 입력하면 골라서 적용할 수 있다. 이름이 없으면 Git은 가장 최근의 Stash를 적용한다.</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git stash apply On branch master Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: index.html modified: lib/simplegit.rb no changes added to commit (use "git add" and/or "git commit -a")</code></pre> </div> </div> <div class="paragraph"> <p>Git은 Stash에 저장할 때 수정했던 파일들을 복원해준다. 복원할 때의 워킹 디렉토리는 Stash 할 때의 그 브랜치이고 워킹 디렉토리도 깨끗한 상태였다. 하지만 꼭 깨끗한 워킹 디렉토리나 Stash 할 때와 같은 브랜치에 적용해야 하는 것은 아니다. 어떤 브랜치에서 Stash 하고 다른 브랜치로 옮기고서 거기에 Stash를 복원할 수 있다. 그리고 꼭 워킹 디렉토리가 깨끗한 상태일 필요도 없다. 워킹 디렉토리에 수정하고 커밋하지 않은 파일들이 있을 때도 Stash를 적용할 수 있다. 만약 충돌이 있으면 알려준다.</p> </div> <div class="paragraph"> <p>Git은 Stash를 적용할 때 Staged 상태였던 파일을 자동으로 다시 Staged 상태로 만들어 주지 않는다. 그래서 <code>git stash apply</code> 명령을 실행할 때 <code>--index</code> 옵션을 주어 Staged 상태까지 적용한다. 그래야 원래 작업하던 상태로 돌아올 수 있다.</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git stash apply --index On branch master Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: index.html Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: lib/simplegit.rb</code></pre> </div> </div> <div class="paragraph"> <p><code>apply</code> 옵션은 단순히 Stash를 적용하는 것뿐이다. Stash는 여전히 스택에 남아 있다. <code>git stash drop</code> 명령을 사용하여 해당 Stash를 제거한다.</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git stash list stash@{0}: WIP on master: 049d078 added the index file stash@{1}: WIP on master: c264051 Revert "added file_size" stash@{2}: WIP on master: 21d80a5 added number to log $ git stash drop stash@{0} Dropped stash@{0} (364e91f3f268f0900bc3ee613f9f733e82aaed43)</code></pre> </div> </div> <div class="paragraph"> <p>그리고 <code>git stash pop</code> 이라는 명령도 있는데 이 명령은 Stash를 적용하고 나서 바로 스택에서 제거해준다.</p> </div> </div> <div class="sect3"> <h3 id="_stash를_만드는_새로운_방법">Stash를 만드는 새로운 방법</h3> <div class="paragraph"> <p>Stash를 만드는 방법은 여러 가지다. 주로 사용하는 옵션으로 <code>stash save</code> 명령과 같이 쓰는 <code>--keep-index</code> 이다. 이 옵션을 이용하면 이미 Staging Area에 들어 있는 파일을 Stash 하지 않는다.</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git status -s M index.html M lib/simplegit.rb $ git stash --keep-index Saved working directory and index state WIP on master: 1b65b17 added the index file HEAD is now at 1b65b17 added the index file $ git status -s M index.html</code></pre> </div> </div> <div class="paragraph"> <p>추적하지 않는 파일과 추적 중인 파일을 같이 Stash 하는 일도 꽤 빈번하다. 기본적으로 <code>git stash</code> 는 추적 중인 파일만 저장한다. 추적 중이지 않은 파일을 같이 저장하려면 Stash 명령을 사용할 때 <code>--include-untracked</code> 나 <code>-u</code> 옵션을 붙여준다.</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git status -s M index.html M lib/simplegit.rb ?? new-file.txt $ git stash -u Saved working directory and index state WIP on master: 1b65b17 added the index file HEAD is now at 1b65b17 added the index file $ git status -s $</code></pre> </div> </div> <div class="paragraph"> <p>끝으로 <code>--patch</code> 옵션을 붙이면 Git은 수정된 모든 사항을 저장하지 않는다. 대신 대화형 프롬프트가 뜨며 변경된 데이터 중 저장할 것과 저장하지 않을 것을 지정할 수 있다.</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git stash --patch diff --git a/lib/simplegit.rb b/lib/simplegit.rb index 66d332e..8bb5674 100644 --- a/lib/simplegit.rb +++ b/lib/simplegit.rb @@ -16,6 +16,10 @@ class SimpleGit return `#{git_cmd} 2>&1`.chomp end end + + def show(treeish = 'master') + command("git show #{treeish}") + end end test Stash this hunk [y,n,q,a,d,/,e,?]? y Saved working directory and index state WIP on master: 1b65b17 added the index file</code></pre> </div> </div> </div> <div class="sect3"> <h3 id="_stash를_적용한_브랜치_만들기">Stash를 적용한 브랜치 만들기</h3> <div class="paragraph"> <p>보통 Stash에 저장하면 한동안 그대로 유지한 채로 그 브랜치에서 계속 새로운 일을 한다. 그러면 이제 저장한 Stash를 적용하는 것이 문제가 된다. 수정한 파일에 Stash를 적용하면 충돌이 일어날 수도 있고 그러면 또 충돌을 해결해야 한다. 필요한 것은 Stash 한 것을 쉽게 다시 테스트하는 것이다. <code>git stash branch <브랜치></code> 명령을 실행하면 Stash 할 당시의 커밋을 Checkout 한 후 새로운 브랜치를 만들고 여기에 적용한다. 이 모든 것이 성공하면 Stash를 삭제한다.</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git stash branch testchanges M index.html M lib/simplegit.rb Switched to a new branch 'testchanges' On branch testchanges Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: index.html Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git checkout -- <file>..." to discard changes in working directory) modified: lib/simplegit.rb Dropped refs/stash@{0} (29d385a81d163dfd45a452a2ce816487a6b8b014)</code></pre> </div> </div> <div class="paragraph"> <p>이 명령은 브랜치를 새로 만들고 Stash를 복원해주는 매우 편리한 도구다.</p> </div> </div> <div class="sect3"> <h3 id="_git_clean">워킹 디렉토리 청소하기</h3> <div class="paragraph"> <p>작업하고 있던 파일을 Stash 하지 않고 단순히 그 파일들을 치워버리고 싶을 때가 있다. <code>git clean</code> 명령이 그 일을 한다.</p> </div> <div class="paragraph"> <p>보통은 Merge나 외부 도구가 만들어낸 파일을 지우거나 이전 빌드 작업으로 생성된 각종 파일을 지우는 데 필요하다.</p> </div> <div class="paragraph"> <p>이 명령을 사용할 때는 신중해야 한다. 이 명령을 사용하면 워킹 디렉토리 안의 추적하고 있지 않은 모든 파일이 지워지기 때문이다. 명령을 실행하고 나서 후회해도 소용없다. 지워진 파일은 돌아오지 않는다. <code>git stash –all</code> 명령을 이용하면 지우는 건 똑같지만, 먼저 모든 파일을 Stash 하므로 좀 더 안전하다.</p> </div> <div class="paragraph"> <p>워킹 디렉토리의 불필요한 파일들을 전부 지우려면 <code>git clean</code> 을 사용한다. 추적 중이지 않은 모든 정보를 워킹 디렉토리에서 지우고 싶다면 <code>git clean -f -d</code> 명령을 사용하자. 이 명령은 하위 디렉토리까지 모두 지워버린다. <code>-f</code> 옵션은 강제(force)의 의미이며 "진짜로 그냥 해라"라는 뜻이다.</p> </div> <div class="paragraph"> <p>이 명령을 실행했을 때 어떤 일이 일어날지 미리 보고 싶다면 <code>-n</code> 옵션을 사용한다. <code>-n</code> 옵션은 “가상으로 실행해보고 어떤 파일들이 지워질지 알려달라” 라는 뜻이다.</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git clean -d -n Would remove test.o Would remove tmp/</code></pre> </div> </div> <div class="paragraph"> <p><code>git clean</code> 명령은 추적 중이지 않은 파일만 지우는 게 기본 동작이다. <code>.gitignore</code> 에 명시했거나 해서 무시되는 파일은 지우지 않는다. 무시된 파일까지 함께 지우려면 <code>-x</code> 옵션이 필요하다. 그래서 <code>.o</code> 파일 같은 빌드 파일까지도 지울 수 있다.</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git status -s M lib/simplegit.rb ?? build.TMP ?? tmp/ $ git clean -n -d Would remove build.TMP Would remove tmp/ $ git clean -n -d -x Would remove build.TMP Would remove test.o Would remove tmp/</code></pre> </div> </div> <div class="paragraph"> <p><code>git clean</code> 이 무슨 짓을 할지 확신이 안들 때는 항상 <code>-n</code> 옵션을 붙여서 먼저 실행해보자. clean 명령을 대화형으로 실행하려면 <code>-i</code> 옵션을 붙이면 된다.</p> </div> <div class="paragraph"> <p>대화형으로 실행한 clean 명령의 모습은 아래와 같다.</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-console" data-lang="console">$ git clean -x -i Would remove the following items: build.TMP test.o *** Commands *** 1: clean 2: filter by pattern 3: select by numbers 4: ask each 5: quit 6: help What now></code></pre> </div> </div> <div class="paragraph"> <p>대화형으로 실행하면 파일마다 지우지 말지 결정하거나 특정 패턴으로 걸러서 지울 수도 있다.</p> </div> <div class="admonitionblock note"> <table> <tr> <td class="icon"> <div class="title">노트</div> </td> <td class="content"> <div class="paragraph"> <p>작업하던 저장소가 완전 지저분해져서 Git에게 진짜로 강제로 정리하도록 해야 하는 경우가 생길 수 있다. 예를 들어 Git 버전관리 데이터가 포함된 디렉토리를 복사해왔거나 서브모듈 디렉토리에 문제가 생겼거나 하는 경우 <code>git clean -fd</code> 옵션으로 실행한 명령이라도 디렉토리 삭제가 되지 않는 경우가 있다. 이런 경우에는 <code>-f</code> 옵션을 한번 더 사용하여 강제성을 추가로 주어야 한다.</p> </div> </td> </tr> </table> </div> </div> <div id="nav"><a href="/book/ko/v2/Git-도구-대화형-명령">prev</a> | <a href="/book/ko/v2/Git-도구-내-작업에-서명하기">next</a></div> </div> </div> </div> </div> <footer> <div class="site-source"> <a href="/site">About this site</a><br> Patches, suggestions, and comments are welcome. </div> <div class="sfc-member"> Git is a member of <a href="/sfc">Software Freedom Conservancy</a> </div> </footer> <a href="#top" class="no-js scrollToTop" id="scrollToTop" data-label="Scroll to top"> <img src="/images/icons/chevron-up@2x.png" width="20" height="20" alt="scroll-to-top"/> </a> <script src="/js/jquery-1.7.1.min.js"></script> <script src="/js/jquery-ui-1.8.18.custom.min.js"></script> <script src="/js/jquery.defaultvalue.js"></script> <script src="/js/session.min.js"></script> <script src="/js/application.min.js"></script> </div> </body> </html>