====== git ====== * 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]] sudo add-apt-repository ppa:git-core/ppa sudo apt update sudo apt install git ===== Client 설정 ===== * https 관련 오류 발생시 ''env GIT_SSL_NO_VERIFY=true'' 붙여서 실행 * 기본 git 사용자 정보 설정 ''git config %%--%%global''이면 전체 시스템 공통 설정 ''%%--%%global'' 빼면 해당 리포지토리 지역 설정 git config --global user.email "your@email.com" git config --global user.name "사용자명" # push/pull 기본설정 - 현재 브랜치에 대해서만 작동 git config --global push.default simple # Windows에서 파일 모드 변경으로 인한 Update 방지 git config --global core.filemode false # Mac OS X 유니코드 문제? 아직도 발생하나? # git config --global core.precomposeunicode true * [[http://resoneit.blogspot.kr/2013/06/git.html|Mac OS X에서 git의 한글 호환 오류 문제 해결하기]] * git 1.7.12 이상 버전 사용 * ''git config %%--%%global core.precomposeunicode true'' * 이걸 해도 자소 분리 현상이 발생하면 ''user.name''을 다시 설정할 것. * 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''에 [includeIf "gitdir:~/my-personal-projects/"] #마지막 "/" 필수 path = .git_personal_projects * ''~/.git_personal_proejcts'' [user] email = kwon37xi@gmail.com name = KwonNamSon * **includeIf 는 맨 마지막에 두는 것이 좋다.** 이 이후에 나오는 설정은 ''includeIf''에 있는 설정을 덮어쓴다. ===== Ubuntu Git 최신 버전 ===== * https://launchpad.net/~git-core/+archive/ubuntu/ppa sudo add-apt-repository ppa:git-core/ppa sudo apt-get update sudo apt-get install git ===== diff & difftool ===== * ''git diff'' 명령에서 실행하는 것이 ''[diff]의 external'' 항목, ''git difftool''에서 실행하는 것이 ''[diff]의 tool'' 항목이다. * ''diff''는 기본값 그대로 두고 ''difftool''을 바꾸자. ''diff''는 pager 를 끼고 실행되는데, GUI diff 를 사용할 경우 pager가 중간에 끼어든다. "pager = " 설정으로 페이저를 없앨 수 있지만, log 등을 볼 때 페이저가 없어서 문제가 된다. * ''-t '' : diff/mergetool을 여러개 지정하고 원하는 이름의 tool 호출 git difftool -t meld git mergetool -t kdiff3 ===== Git Diff/Merge -> kdiff3 ===== * [[https://docs.kde.org/trunk5/en/extragear-utils/kdiff3/git.html|Using KDiff3 as a Git Diff and Merging Tool]] * 파일 삭제 diff시에 잘 작동 안함. * https://github.com/KDE/kdiff3/blob/master/ChangeLog : Version 1.8.3 부터 해결됨. [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 ===== Git Difftool/Mergetool -> meld ===== * http://wiredforcode.com/blog/2011/06/04/git-with-meld-diff-viewer-on-ubuntu/ : ''diff''를 바꾸는 방식 * [[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로 사용하는 간결한 설정. # ------------------ M E R G E ------------------------- [merge] tool = meld [mergetool "meld"] cmd = meld --auto-merge \"$LOCAL\" \"$BASE\" \"$REMOTE\" --output \"$MERGED\" --label \"MERGE (REMOTE BASE MY)\" trustExitCode = false [mergetool] # don't ask if we want to skip merge prompt = false # don't create backup *.orig files keepBackup = false # ------------------ D I F F ------------------------- [diff] guitool = meld [difftool "meld"] cmd = meld \"$LOCAL\" \"$REMOTE\" --label \"DIFF (ORIGINAL MY)\" ===== Git Diff -> vimdiff ===== * [[vim:vimdiff|vimdiff]] * [[http://technotales.wordpress.com/2009/05/17/git-diff-with-vimdiff/|Git Diff with Vimdiff]] * ''~/.gitconfig'' [diff] external = git_diff_wrapper [pager] diff = * ''~/bin/git_diff_wrapper'' #!/bin/sh vimdiff "$2" "$5" * 설정의 external 무시하고 vim을 pager로 git diff --no-ext-diff -w | vim -R - * 그냥 명령을 직접 주기 git diff -y -t vimdiff # -y 는 no prompt ===== .gitignore ===== *.exe # 모든 .exe 파일을 ignore 하되 !node.exe # node.exe 는 ignore 하지 않는다. 상위 설정을 아래에서 덮어씀. ===== Global .gitignore ===== # Create a ~/.gitignore in your user directory cd ~/ touch .gitignore # Exclude bin and .metadata directories echo "bin" >> .gitignore echo ".metadata" >> .gitignore echo "*~" >> .gitignore echo "target/" >> .gitignore # Configure Git to use this file # as global .gitignore git config --global core.excludesfile ~/.gitignore ===== Commit Template ===== ''$HOME/.gitmessage.txt'' 파일에 기본 커밋 메시지를 작성해 두고서, git config --global commit.template $HOME/.gitmessage.txt ===== https certificat problem ===== * 특히 윈도우 Cygwin에서 아르와 같은 오류가 발생한다. https로 clone할 때. Cloning into 'projectName'... error: error setting certificate verify locations: CAfile: /usr/ssl/certs/ca-bundle.crt CApath: none while accessing https://code.google.com/p/projectName/info/refs fatal: HTTP request failed * [[http://stackoverflow.com/questions/3777075/ssl-certificate-rejected-trying-to-access-github-over-https-behind-firewall|git - SSL certificate rejected trying to access GitHub over HTTPS behind firewall]] * 해결책 1 - SSL 인증 무시 # 환경변수로 무시 export GIT_SSL_NO_VERIFY=true # 아니면 GIT 설정으로 무시 git config --global http.sslVerify false * 인증서 깔아주기 mkdir ~/certs curl http://curl.haxx.se/ca/cacert.pem -o ~/certs/cacert.pem # ~/.gitconfig 편집 [http] sslCAinfo = /home/radium/certs/cacert.pem ===== 독립 리포지토리 여러개를 하나로 묶기 ===== * http://stackoverflow.com/questions/614229/can-i-move-the-git-directory-for-a-repo-to-its-parent-directory * 보통 독립 프로젝트 여러개의 하나의 멀티 모듈 프로젝트로 변경할 때 필요. ===== Bash Prompt ===== * [[linux:powerline|Powerline]] 사용시 bash 테마를 ''default_leftonly''로 지정하면 아래 과정이 불필요하다. * [[http://code-worrier.com/blog/git-branch-in-bash-prompt/|Bash 프롬프트에 Git Branch 이름 보여주기]] mkdir -p ~/.local/bin curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh -o ~/.local/bin/git-prompt.sh # edit .bashrc source ~/.local/bin/git-prompt.sh export PS1='이런저런 내용 \$(__git_ps1) 나머지 ' # 실예 녹색 프롬프트 export PS1='\[\e[1;32m\][\u@\h \W$(__git_ps1)]\$\[\e[0m\] ' # 실예 컬러 프롬프트 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\] " ===== bash auto completion ===== * 대부분의 리눅스는 git 을 설치하면 이미 bash-completion 설정 파일을 함께 설치한다. source /etc/bash_completion.d/git # or source /usr/share/bash-completion/completions/git * [[https://github.com/bobthecow/git-flow-completion/wiki/Install-Bash-git-completion|Install Bash git completion · bobthecow/git-flow-completion Wiki]] * Arch/Manjaro sudo pacman -S git bash-completion # shell 재실행 ===== 환경변수 ===== * ''GIT_CURL_VERBOSE=1'' : HTTP(S)에서 cURL 요청 주고 받는 것을 콘솔에 출력한다. ===== 문제 해결 ===== ==== HTTP(S) 에서 비밀번호를 물어보지 않음 ==== * [[http://stackoverflow.com/questions/9186835/git-bash-for-windows-not-prompting-for-password|version control - Git bash for Windows NOT prompting for password]] * 정확히 문제점은 파악이 안된 상태이고, 로컬 저장소의 ''.git/config'' 파일의 Remote URL에서 ''username@''을 제거한다. * LDAP 연동상황에서 비밀번호를 변경했더니 되기도 하였다. ===== Git Hosting ===== * [[git:github|Github]] * [[git:codebreak|CodeBreak]] private hosting 무료 * [[git:bitbucket|BitBucket]] private hosting 무료 ===== Git 관련 애플리케이션 ===== * [[https://git.wiki.kernel.org/index.php/Interfaces,_frontends,_and_tools|Git Interfaces, frontends and tools]] * [[git:gitblit|Gitblit]] : 소규모 팀에서 사용하기 좋음. 설치가 매우 쉽고, groovy로 hook 가능. * [[git:giteye|GitEye]] * [[http://gitlab.org/|GitLab]] : 어느정도 대규모 팀도 가능, 다양한 기능. 자주 멈춤현상 발생. * [[https://github.com/sitaramc/gitolite|gitolite]] Git 중앙 Repository 구축 * [[https://github.com/takezoe/gitbucket|GitBucket]] Scala로 만들어진 Github 클론. Git Repository 구축 * [[http://subgit.com/index.html|SubGit]] SVN/Git 리포지토리 동기화를 통해 SVN과 Git을 동시에 사용할 수 있게 해준다. SVN에서 Git으로 옮기는 과도기에 사용할 수 있다. * [[http://www.pickysysadmin.ca/2013/03/25/how-to-install-gitlab-5-0-on-centos-6/|How to install Gitlab 5.0 on CentOS 6 or RHEL6]] * [[http://code.google.com/p/gerrit/|Gerrit]] Git 기반 코드 리뷰 툴 * [[https://live.gnome.org/giggle|Giggle]] GTK+ Git 관리 * [[https://live.gnome.org/Gitg|Gitg]] GTK+ 리포지토리 브라우저 * [[git:tig|tig]] 콘솔 기반 리포지토리 브라우저 * [[https://github.com/FredrikNoren/ungit|ungit]] 웹기반 Git 인터페이스 * [[http://gitignore.io/|gitignore.io]] 자동으로 ''.gitignore'' 파일을 생성해준다. * [[http://gitstats.sourceforge.net/|GitStats - git history statistics generator]] * [[https://rhodecode.com/|RhodeCode]] * [[http://yobi.io/|Yobi]] Git 지원 협업 프로젝트 관리 툴 * [[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) 유지 ===== * ''.gitkeep'' 파일을 만들어 둔면 된다. * [[https://stackoverflow.com/questions/115983/how-can-i-add-an-empty-directory-to-a-git-repository|How can I add an empty directory to a Git repository? - Stack Overflow]] find . -type d -empty -exec touch {}/.gitkeep \; ===== 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)]] git fetch --unshallow origin # 이후에 git push ===== 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'' 옵션 필요 git clone --recursive ===== 문제 해결 ===== * [[http://ohshitgit.com/|Oh, shit, git!]] ===== 참조 ===== * [[http://jonas.nitro.dk/git/quick-reference.html|git Quick Reference]] * [[http://gitref.org/|Git Reference]] * [[http://resoneit.blogspot.kr/2013/03/svn-git.html|resoneit: svn 능력자를 위한 git 개념 가이드]] * [[http://juristr.com/blog/2013/04/git-explained/|Git for Beginners]] * [[http://try.github.com/|Try Git]] * [[http://dogfeet.github.com/articles/2012/progit.html|Pro Git 번역]] * [[http://java.dzone.com/articles/my-git-setup-windows|My Git setup on windows]] * [[http://ioriy2k.pe.kr/archives/5935|Ubuntu에 Git 설치하기 1]] [[http://ioriy2k.pe.kr/archives/6097|2]] * [[http://dogfeet.github.com/articles/2013/git-password-caching.html|git: password caching]] * [[http://rogerdudler.github.com/git-guide/index.ko.html|git 간편 안내서]] * [[http://dogfeet.github.com/articles/2012/git-secrets.html|Git: git secrets]] * [[http://dogfeet.github.com/articles/2012/git-github-secrets.html|Git: GitHub secrets]] * [[http://net.tutsplus.com/tutorials/tools-and-tips/git-tips-from-the-pros/|Git Tips From the Pros]] * [[http://pcottle.github.com/learnGitBranching/|Learn Git Branching]] * [[http://wangsy.com/blog/2011/12/git-guide/|Git Guide]] * [[http://john.albin.net/git/convert-subversion-to-git|Converting a Subversion repository to Git, (7 steps to migrate a complete mirror of svn in git)]] * [[http://dogfeet.github.io/articles/2012/git-global-ignore.html|Git: Global Ignore]] * [[http://gypark.pe.kr/wiki/Git|gypark.pe.kr Git 정리]] * [[https://github.com/pluralsight/git-internals-pdf|Git Internals]] * [[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 안내서]]