-
소소한 Git ( 및 기본 terminal 명령어 )Private Memo 2021. 11. 2. 01:47
(Working Directory -> ) Staging Area 에 현재 폴더 내 모든 파일 추가
git add .
(Staging Area -> )Local Repository 로 msg 를 남기며 이동.
git commit -m "<msg>"
(Local Repository -> ) Remote Repository 로 이동.
git push -u origin <branch>
(The -u flag is used to set origin as the upstream remote in your git config. As you push a branch successfully or up to date it, it adds upstream reference. As you push local branch with (the) git push -u option, that local branch is linked with the remote branch automatically.)
<url> 에 위치한 <short_name> 에 remote 생성. 이후에는 url 없이 <short_name> 으로 사용.
( git remote add origin http://github.com/hanmok/myProject.git )
git remote add <short_name> "<url>"
What is git push origin master?
This is a command that says "push the commits in the local branch named master to the remote named origin"
<name> branch 생성. (새로 작업할 기능 등)
git branch <name>
<name> 을 가진 branch 로 이동
git checkout <name>
branch 를 생성하면서 동시에 이동하기.
git checkout -b <branch_name>
remote address 지우기
git remote remove origin
git remote address 조회하기
git remote show origin
폴더 ( 그 내부에 있는 내용물들까지 ) 제거
rm -r <dirName> meaning reculsively remove <dirName>
현재 local repository 에 덮어쓰기
git fetch origin master git reset --hard origin/master
Commit Message 변경
Command line 에서 원하는 repository (수정하고 싶은 commit 이 있는 곳) 으로 이동,
git commit --amend
입력, Terminal 내 TextEditor 에서 commit message 수정.
TextEditor 에서 나갈 때는 ?
:wq
git branch 제거
git branch -d <branch_name>
Delete a branch with git branch -d <branch> . The -d option will delete the branch only if it has already been pushed and merged with the remote branch. Use -D instead if you want to force the branch to be deleted, even if it hasn't been pushed or merged yet. The branch is now deleted locally.2020. 1. 2.
현재 변경 내용 제거 (local, unstaged)
git reset --hard
Commit 후 Push 되지 않은 것 Commit 지우기.
1. 현재까지 한 것 남길 때
git reset --soft HEAD~1
2. 현재까지 한 것 없앨 때
git reset --hard HEAD~1
실수로
git reset --hard
등을 써서 여태 작업한 것을 날려먹었을 때..
https://stackoverflow.com/questions/5473/how-can-i-undo-git-reset-hard-head1
How can I undo git reset --hard HEAD~1?
Is it possible to undo the changes caused by the following command? If so, how? git reset --hard HEAD~1
stackoverflow.com
git reflog
git fsck --lost-found
등을 이용해 되찾을 수 있다.
GIT LAB
stale branch
a branch that has not had any commits in the previous 3 months.
모든 Branch 가져오기
git branch -r | grep -v '\->' | while read remote; do git branch --track "${remote#origin/}" "$remote"; done git fetch --all git pull --all
Commit Msg 수정하기
git commit --amend
Git ignore ( Swift )
Git ignore file 을 추가하면, 불필요하게 Commit 해야 하는 필요를 줄일 수 있고, 보안을 강화할 수 있는 등의 이점이 있다. (API Key 등을 Remote 에 저장하지 않을 수 있음 )
(가끔 .DS_Store 가 commit 된 후 남아있고 변하게 되면 이 쓸데없는 파일 하나때문에 Commit 을 더 해야하는 상황 발생.. )
우선, 추천하는 Git ignore file 은
https://github.com/github/gitignore/blob/main/Swift.gitignore
GitHub - github/gitignore: A collection of useful .gitignore templates
A collection of useful .gitignore templates. Contribute to github/gitignore development by creating an account on GitHub.
github.com
에서 찾을 수 있다.
Github 에서 Gitignore 검색, 그 안에 있는 Swift 전용 gitignoreFile
# Xcode # # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore ## User settings xcuserdata/ ## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) *.xcscmblueprint *.xccheckout ## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) build/ DerivedData/ *.moved-aside *.pbxuser !default.pbxuser *.mode1v3 !default.mode1v3 *.mode2v3 !default.mode2v3 *.perspectivev3 !default.perspectivev3 ## Obj-C/Swift specific *.hmap ## App packaging *.ipa *.dSYM.zip *.dSYM ## Playgrounds timeline.xctimeline playground.xcworkspace # Swift Package Manager # # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. # Packages/ # Package.pins # Package.resolved # *.xcodeproj # # Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata # hence it is not needed unless you have added a package configuration file to your project # .swiftpm .build/ # CocoaPods # # We recommend against adding the Pods directory to your .gitignore. However # you should judge for yourself, the pros and cons are mentioned at: # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control # # Pods/ # # Add this line if you want to avoid checking in source code from the Xcode workspace # *.xcworkspace # Carthage # # Add this line if you want to avoid checking in source code from Carthage dependencies. # Carthage/Checkouts Carthage/Build/ # Accio dependency management Dependencies/ .accio/ # fastlane # # It is recommended to not store the screenshots in the git repo. # Instead, use fastlane to re-generate the screenshots whenever they are needed. # For more information about the recommended setup visit: # https://docs.fastlane.tools/best-practices/source-control/#source-control fastlane/report.xml fastlane/Preview.html fastlane/screenshots/**/*.png fastlane/test_output # Code Injection # # After new code Injection tools there's a generated folder /iOSInjectionProject # https://github.com/johnno1962/injectionforxcode iOSInjectionProject/
이것을 반영하는 방법은,
.gitignore 파일 생성
touch .gitignore
그리고 해당 파일 열어서 위 텍스트를 복붙
open .gitignore
이미 Commit 하지 않은 상태라면 이 상태에서 바로 add, commit 과정을 거치면 완료.
반대로, 이미 Git 을 이용해 작업중이라면,
먼저 현재 프로젝트의 파일들 중 ignore 해야 하는 파일들을 remote 에서 제거한다.
git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached
그리고 add, commit 을 마저 하면 끝 !!
tip:
git ls-files -ci --exclude-standard
을 치면 gitignore 에 해당하는, 이미 commit. 된 파일들의 이름을 출력한다.
출처: https://stackoverflow.com/questions/7527982/applying-gitignore-to-committed-files
Force Merge
https://stackoverflow.com/questions/40517129/git-merge-with-force-overwrite
Git merge with force overwrite
I have a branch called demo which I need to merge with master branch. I can get the desired result with following commands: git pull origin demo git checkout master git pull origin master git merg...
stackoverflow.com
'Private Memo' 카테고리의 다른 글
기타 커맨드 (0) 2021.11.10