사용자 도구

사이트 도구


git

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
git [2018/05/09 11:26]
kwon37xi [Windows Git]
git [2023/10/14 13:47] (현재)
kwon37xi
줄 1: 줄 1:
 ====== git ====== ====== git ======
   * http://git-scm.com/   * http://git-scm.com/
 +  * [[git:cheatsheet|Git Cheatsheet]]
 +  * [[git:credential|git credential]]
 +  * [[https://ohmygit.org|OhMyGit]] - 게임으로 Git 배우기
 +
 +===== Ubuntu 최신 버전 install =====
 +  * [[https://itsfoss.com/install-git-ubuntu/|How to Install the Latest Git Version on Ubuntu]]
 +  * [[https://launchpad.net/~git-core/+archive/ubuntu/ppa|git-core/ppa]]
 +<code sh>
 +sudo add-apt-repository ppa:git-core/ppa
 +sudo apt update
 +sudo apt install git
 +</code>
  
 ===== Client 설정 ===== ===== Client 설정 =====
줄 14: 줄 26:
 git config --global core.filemode false git config --global core.filemode false
  
-# Mac OS X 유니코드 문제 +# Mac OS X 유니코드 문제? 아직도 발생하나? 
-git config --global core.precomposeunicode true +git config --global core.precomposeunicode true 
  
 </code> </code>
줄 24: 줄 36:
     * SourceTree 사용자는 Preferences에서 **"Allow SourceTree to modify your global Mercurial and Git configuration files"** 체크 **해제**     * SourceTree 사용자는 Preferences에서 **"Allow SourceTree to modify your global Mercurial and Git configuration files"** 체크 **해제**
  
 +===== Directory별 Include 설정 =====
 +  * [[https://git-scm.com/docs/git-config#_includes|Git - git-config Documentation]] ''IncludeIf'' 구문으로 작업 디렉토리별로 기본 git 설정을 할 수 있다. 
 +  * [[https://blog.outsider.ne.kr/1448?fbclid=IwAR2FDARy9VIerwVbPjpzXNv03aS58xRFFAMXnP5TrqxUZ6ZgT_OJqh7QfSs|Git 계정 여러 개 동시 사용하기]]
 +  * ''~/.gitconfig''에<code>
 +[includeIf "gitdir:~/my-personal-projects/"] #마지막 "/" 필수
 +  path = .git_personal_projects
 +</code>
 +  * ''~/.git_personal_proejcts''<code>
 +[user]
 +  email = kwon37xi@gmail.com
 +  name = KwonNamSon
 +</code>
 +  * **includeIf 는 맨 마지막에 두는 것이 좋다.** 이 이후에 나오는 설정은 ''includeIf''에 있는 설정을 덮어쓴다.
 ===== Ubuntu Git 최신 버전 ===== ===== Ubuntu Git 최신 버전 =====
   * https://launchpad.net/~git-core/+archive/ubuntu/ppa<code sh>   * https://launchpad.net/~git-core/+archive/ubuntu/ppa<code sh>
줄 31: 줄 56:
 </code> </code>
  
-===== Windows Git ===== +===== diff & difftool ===== 
-  * https://git-scm.com/downloads +  * ''git diff'' 명령에서 실행하는 것이 ''[diff]의 external'' 항목, ''git difftool''에서 실행하는 것이 ''[diff]의 tool'' 항목이다
-  * [[http://guides.beanstalkapp.com/version-control/git-on-windows.html|Working with Git on Windows  •  Beanstalk Guides]] +  * ''diff''는 기본값 그대로 두고 ''difftool''을 바꾸자''diff''는 pager 를 끼고 실행되는데, GUI diff 를 사용할 우 pager가 중간에 끼어든다. "pager = " 설정으로 페를 없앨 수 있지만log 등을 볼 때 저가 없어서 문제가 된다
-  * [[https://msysgit.github.io/|MsysGit]] [[mingw|MinGW]] 와 함께 사용하는 git 클라이언트 +  * ''-<difftool/mergetool이름>'' diff/mergetool을 여러개 지정하고 원하는 이름의 tool 호출
-  * Msys 환경에서 한글이 깨질 때<code sh> +
-# mintty 콘솔이 CP949일 때는 다음 처리를 하고UTF-8일 는 --unset 해버린다. +
-git config --global core.quotepath false # 파일명이 숫자로 보이는 문제 +
-git config --global i18n.logoutputencoding cp949 +
-git config --global i18n.commitencoding cp949 +
-</code> +
-    * [[http://stackoverflow.com/questions/5854967/git-msysgit-accents-utf-8-the-definitive-answers|utf 8 - git, msysgit, accents, utf-8, the definitive answers]] +
-    * [[https://github.com/msysgit/msysgit/wiki/Git-for-Windows-Unicode-Support|Git for Windows Unicode Support]] +
-    *  +
-  * [[http://stackoverflow.com/questions/20238883/git-diff-and-meld-on-windows|msysgit - Git Diff and Meld on Windows]]<code sh> +
-git config --global merge.tool meld +
-git config --global mergetool.meld.cmd 'meld.exe \"$BASE\" \"$LOCAL\" \"$REMOTE\" \"$MERGED\"'+
  
-git config --global diff.tool meld +<code sh> 
-git config --global difftool.meld.cmd 'meld.exe \"$LOCAL\" \"$REMOTE\"'+git difftool -meld 
 +git mergetool -t kdiff3
 </code> </code>
-    위 작업을 하고 나서 ''~/.gitconfig'' 파일을 열어보면 환경변수들이 ''\\\"$LOCAL\\\"'' 처럼 이스케잎 돼 있는데, 이를 역슬래시와 쌍따옴표를 모두 거하여 ''$LOCAL'' 처럼 만들어준다+===== Git Diff/Merge -> kdiff3 ===== 
-    * meld 경로는 '' \<nowiki>"</nowiki>C:/Program Files (x86)/Meld/meld/meld.exe\<nowiki>"</nowiki>'' 처럼 full path로 바꿔줘도 좋다. +  [[https://docs.kde.org/trunk5/en/extragear-utils/kdiff3/git.html|Using KDiff3 as a Git Diff and Merging Tool]] 
-  [[windows:ssh:putty|Putty]]에서  +  * 파일 제 diff시에 잘 작동 안함
-    * ''plink''로 SSH 등록<code> +    * https://github.com/KDE/kdiff3/blob/master/ChangeLog :  Version 1.8.3 부터 해결됨. 
-GIT_SSH=c:\Program Files\Putty\plink.exe+<code> 
 +[diff] 
 +        tool = kdiff3 
 +[difftool "kdiff3"
 +        path = /usr/bin/kdiff3 
 +[difftool] 
 +        prompt = false 
 +        keepBackup = false 
 +        trustExitCode = false 
 +[merge] 
 +        tool = kdiff3 
 +[mergetool
 +        prompt = false 
 +        keepBackup false 
 +        keepTemporaries = false 
 +[mergetool "kdiff3"
 +        path = /usr/bin/kdiff3
 </code> </code>
-    * ''puttygen'' 으로 OpenSSH로 생성된 private key를 ''.ppk'' 파일로 변환하고, 
-    * ''pageant''로 Private Key를 등록해 둔다. 
-    * 새로운 호스트에서 clone을 하려면 먼저 ''putty''로 서버측 인증서를 등록해둬야 한다.<code sh> 
-plink.exe git@github.com 
-</code> 
-    * [[intellij_idea|IntelliJ IDEA]]에서 사용시 ''Version Control -> Git -> SSH Executable''을 ''Native''로 변경한다. 
-===== Password Cache ===== 
-  * HTTP(S) 프로토콜의 경우 명령행에서는 비밀번호 저장해두기가 곤란하다. 그래서 캐시를 사용한다. 
-  * [[http://dogfeet.github.io/articles/2013/git-password-caching.html|Git Password Caching]] 
-  * Linux에서는 다음 처리로 간편하게 캐시가 끝난다.<code sh> 
-# 기본 캐시 시간 15분 
-git config --global credential.helper cache 
  
-# 캐시 시간 지정 +===== Git Difftool/Mergetool -> meld ===== 
-git config --global credential.helper 'cache --timeout=7200+  * http://wiredforcode.com/blog/2011/06/04/git-with-meld-diff-viewer-on-ubuntu/''diff''를 바꾸는 방식 
-</code>+  * [[https://stackoverflow.com/a/34119867/1051402|Git difftool의 기본과 meld설정에 대한 자세한 설명]] 
 +  * [[http://blog.marcinchwedczuk.pl/use-meld-as-git-merge-diff-tool|How to use Meld as git merge and diff tool]] : ''meld''를 difftool과 mergetool로 사용하는 간결한 설정.
  
-===== Password with Gnome-Keyring  ===== +<code> 
-  * [[http://blog.iqandreas.com/git/storing-https-authentication-in-ubuntu-and-arch-linux/|GIT: Storing HTTPS Authentication in Ubuntu (and Arch Linux) The Programming Blog of Andreas Renberg (IQAndreas)]]<code sh> +# ------------------ M E R G E ------------------------- 
-# on Ubuntu +[merge] 
-sudo apt-get install libgnome-keyring-dev +    tool = meld
-sudo make --directory=/usr/share/doc/git/contrib/credential/gnome-keyring +
-git config --global credential.helper /usr/share/doc/git/contrib/credential/gnome-keyring/git-credential-gnome-keyring +
-</code>+
  
-===== Password in Windows =====+[mergetool "meld"
 +    cmd meld --auto-merge \"$LOCAL\" \"$BASE\" \"$REMOTE\" --output \"$MERGED\" --label \"MERGE (REMOTE BASE MY)\" 
 +    trustExitCode false
  
-  * [[https://github.com/Microsoft/Git-Credential-Manager-for-Windows|Git credential manager for windows]]+[mergetool] 
 +    # don't ask if we want to skip merge 
 +    prompt = false
  
-===== Git Diff -> meld ===== +    # don't create backup *.orig files 
-  * http://wiredforcode.com/blog/2011/06/04/git-with-meld-diff-viewer-on-ubuntu/ +    keepBackup false 
-  * ''git-diff-meld.sh''<code sh> + 
-#!/bin/sh +# ------------------ D I F F ------------------------- 
-meld "$2" "$5" > /dev/null 2>&+[diff] 
-</code> +    guitool = meld
-  * add to ''~/.gitconfig''<code> +
-git config --global diff.external '/path/to/git-diff-meld.sh' +
-</code>+
  
-===== Git Mergetool -> meld ===== +[difftool "meld"
-  * 전역 설정 <code sh> +    cmd = meld \"$LOCAL\" \"$REMOTE\" --label \"DIFF (ORIGINAL MY)\"
-git config --global merge.tool meld+
 </code> </code>
  
 ===== Git Diff -> vimdiff ===== ===== Git Diff -> vimdiff =====
 +  * [[vim:vimdiff|vimdiff]]
   * [[http://technotales.wordpress.com/2009/05/17/git-diff-with-vimdiff/|Git Diff with Vimdiff]]   * [[http://technotales.wordpress.com/2009/05/17/git-diff-with-vimdiff/|Git Diff with Vimdiff]]
   * ''~/.gitconfig''<code>   * ''~/.gitconfig''<code>
줄 115: 줄 132:
   * 설정의 external 무시하고 vim을 pager로<code sh>   * 설정의 external 무시하고 vim을 pager로<code sh>
 git diff --no-ext-diff -w | vim -R - git diff --no-ext-diff -w | vim -R -
 +</code>
 +  * 그냥 명령을 직접 주기<code sh>
 +git diff -y -t vimdiff
 +# -y 는 no prompt
 </code> </code>
 ===== .gitignore ===== ===== .gitignore =====
줄 140: 줄 161:
 </code> </code>
  
-===== Git hook ===== 
-  * 기본적으로는 ''projectdir/.git/hooks''에 후킹 파일을 둔다. 
-  * 전역 Hook 파일 설정 (git 2.9+)<code sh> 
-git config --global core.hooksPath /path/to/my/centralized/hooks 
-</code> 
  
 ===== Commit Template ===== ===== Commit Template =====
줄 185: 줄 201:
   * [[linux:powerline|Powerline]] 사용시 bash 테마를 ''default_leftonly''로 지정하면 아래 과정이 불필요하다.   * [[linux:powerline|Powerline]] 사용시 bash 테마를 ''default_leftonly''로 지정하면 아래 과정이 불필요하다.
   * [[http://code-worrier.com/blog/git-branch-in-bash-prompt/|Bash 프롬프트에 Git Branch 이름 보여주기]]<code sh>   * [[http://code-worrier.com/blog/git-branch-in-bash-prompt/|Bash 프롬프트에 Git Branch 이름 보여주기]]<code sh>
 +mkdir -p ~/.local/bin
 curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh -o ~/.local/bin/git-prompt.sh curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh -o ~/.local/bin/git-prompt.sh
  
줄 196: 줄 213:
 export PS1="\[\033[01;32m\][\[\033[01;33m\]\u\[\033[01;36m\]@\[\033[01;31m\]\h\[\033[01;37m\]:\[\033[01;34m\]\w\[\033[01;32m\]\$(__git_ps1)]\[\033[01;35m\]\\$\[\033[00m\] " export PS1="\[\033[01;32m\][\[\033[01;33m\]\u\[\033[01;36m\]@\[\033[01;31m\]\h\[\033[01;37m\]:\[\033[01;34m\]\w\[\033[01;32m\]\$(__git_ps1)]\[\033[01;35m\]\\$\[\033[00m\] "
  
 +</code>
 +
 +===== bash auto completion =====
 +  * 대부분의 리눅스는 git 을 설치하면 이미 bash-completion 설정 파일을 함께 설치한다.<code sh>
 +source /etc/bash_completion.d/git
 +# or
 +source /usr/share/bash-completion/completions/git
 +</code>
 +  * [[https://github.com/bobthecow/git-flow-completion/wiki/Install-Bash-git-completion|Install Bash git completion · bobthecow/git-flow-completion Wiki]]
 +  * Arch/Manjaro <code>
 +sudo pacman -S git bash-completion
 +# shell 재실행
 </code> </code>
  
줄 224: 줄 253:
   * [[https://live.gnome.org/giggle|Giggle]] GTK+ Git 관리   * [[https://live.gnome.org/giggle|Giggle]] GTK+ Git 관리
   * [[https://live.gnome.org/Gitg|Gitg]] GTK+ 리포지토리 브라우저   * [[https://live.gnome.org/Gitg|Gitg]] GTK+ 리포지토리 브라우저
-  * [[http://jonas.nitro.dk/tig/|tig]] 콘솔 기반 리포지토리 브라우저+  * [[git:tig|tig]] 콘솔 기반 리포지토리 브라우저
   * [[https://github.com/FredrikNoren/ungit|ungit]] 웹기반 Git 인터페이스   * [[https://github.com/FredrikNoren/ungit|ungit]] 웹기반 Git 인터페이스
   * [[http://gitignore.io/|gitignore.io]] 자동으로 ''.gitignore'' 파일을 생성해준다.   * [[http://gitignore.io/|gitignore.io]] 자동으로 ''.gitignore'' 파일을 생성해준다.
줄 231: 줄 260:
   * [[http://yobi.io/|Yobi]] Git 지원 협업 프로젝트 관리 툴   * [[http://yobi.io/|Yobi]] Git 지원 협업 프로젝트 관리 툴
   * [[http://www.maketecheasier.com/6-useful-graphical-git-client-for-linux/|6 Useful Graphical Git Client for Linux]]   * [[http://www.maketecheasier.com/6-useful-graphical-git-client-for-linux/|6 Useful Graphical Git Client for Linux]]
 +  * [[https://gogs.io|gogs]] self hosted git server
  
 ===== 빈 디렉토리 (empty directory) 유지 ===== ===== 빈 디렉토리 (empty directory) 유지 =====
줄 237: 줄 267:
 <code sh> <code sh>
 find . -type d -empty -exec touch {}/.gitkeep \; find . -type d -empty -exec touch {}/.gitkeep \;
 +</code>
 +
 +===== Windows 등에서 파일 chmod 변경 - 특히 실행(x) 권한 =====
 +  * [[https://medium.com/@akash1233/change-file-permissions-when-working-with-git-repos-on-windows-ea22e34d5cee|Change file permissions when working with git repo’s on windows]] 윈도우에 파일 mod 변경하기
 +  * 아래는 Linux/*nix 계열에서는 불필요하고 작동하지도 않았다. 그냥 ''chmod'' 명령을 직접사용하면됨.
 +  * ''git ls-files %%--%%stage'' 명령으로 파일 권한 확인. 보통 ''100644''로 돼 있음.
 +  * ''git update-index %%--chmod=+x%% 'name-of-shell-script''' : 권한에 ''x'' 추가
 +  * ''git ls-files %%--%%stage''로 다시 확인해보면 **100755**로 변경됨.
 +  * commit 한다.
 +
 +===== shallow update not allowed =====
 +  * ''clone --depth=x'' 로 클론한 로컬 리포지토리에서 수정해서 push 하면 ''! [remote rejected] master -> master (shallow update not allowed)'' 오류가 발생한다.
 +  * [[https://stackoverflow.com/questions/28983842/remote-rejected-shallow-update-not-allowed-after-changing-git-remote-url|! [remote rejected] master -> master (shallow update not allowed)]]
 +
 +<code sh>
 +git fetch --unshallow origin
 +
 +# 이후에
 +git push
 +</code>
 +
 +
 +===== git blame ignore =====
 +  * [[https://www.moxio.com/blog/43/ignoring-bulk-change-commits-with-git-blame|Ignoring bulk change commits with git blame - Moxio]]
 +  * bulk 갱신, 포맷팅 변경 같은 경우 blame 에 자꾸 나오면 오히려 불편함. 특정 commit 을 blame에서 제외하기
 +  * [[https://akrabat.com/ignoring-revisions-with-git-blame/|Ignoring mass reformatting commits with git blame – Rob Allen's DevNotes]]
 +
 +===== submodules =====
 +  * git 에서 다른 리포지토리를 디렉토리로 링크할 수 있음.
 +  * https://git-scm.com/book/en/v2/Git-Tools-Submodules
 +  * submodule 이 있는 리포지토리를 올바로 clone 하려면 ''--recursive'' 옵션 필요
 +
 +<code sh>
 +git clone --recursive <repos-url>
 </code> </code>
  
줄 263: 줄 327:
   * [[https://github.com/pluralsight/git-internals-pdf|Git Internals]]   * [[https://github.com/pluralsight/git-internals-pdf|Git Internals]]
   * [[http://www-cs-students.stanford.edu/~blynn/gitmagic/|git magic]]   * [[http://www-cs-students.stanford.edu/~blynn/gitmagic/|git magic]]
 +  * [[https://www.cyberciti.biz/open-source/github-alternatives-open-source-seflt-hosted/|6 Github alternatives that is open source and self-hosted - nixCraft]]
 +  * [[https://johngrib.github.io/wiki/git-alias/|편리한 git alias 설정하기 - 기계인간 John Grib]]
 +  * [[https://blog.ull.im/engineering/2019/03/10/logs-on-git.html|좋은 git commit 메시지를 위한 영어 사전]]
 +  * [[https://www.javacodegeeks.com/2019/10/git-essentials-crash-course.html|Git Essentials Crash Course | Java Code Geeks - 2019]]
 +  * [[https://github.com/mingrammer/git-tips|Git Tips]]
 +  * [[https://github.com/ingydotnet/git-subrepo|ingydotnet/git-subrepo]]
 +  * [[https://subicura.com/git/|Git / GitHub 안내서]]
git.1525832786.txt.gz · 마지막으로 수정됨: 2018/05/09 11:26 저자 kwon37xi