about Git

JoongHyun's Blog·2023년 3월 28일
1

각각의 버전은, 버전이 만들어진 시점의 stage area의 snap shot

parent = Head가 가르키는것.

master = 마지막 시점.

branch = 재 작업 환경에 이름을 붙이는것 master가 여러가지.

git push 를 하면 이렇게 origin이 따라온다.



main도 push해주면 따라온다.


병합은 어떻게 될까요?

main에서 exp1을 병합하면 exp1은 그대로 두고 main을 합치게 됩니다.


to be continue

  1. make remote repo
  2. git clone remote reop to local
  3. commit in local

git config --global alias.l "log --oneline --all --graph"

= git l

git graph
git status
git add [file name]
add : untracked -> tracked

git commit -m "[commit message]"
git commit -a -m "[commit message]"
git commit -am "[commit message]"
-a : tracked만 auto adding

.gitigonre = .gitignore된 파일을 어떻게 관리 할까?

git reset --hard , --mixed, --soft

checkout = HEAD를 바꾼다.
reset = HEAD의 Branch를 바꾼다.

git reset :
if(attached HEAD){
HEAD의 branch
} else {
=== checkout
}

git reflog : 여태까지 모든 작업한 내용 모두 보여줌.

git reset --hard, --mixed --soft

git reset --hard HEAD@{1} 
이전에 했던 작업 취소 가능

현재 마지막을 보면 branch는 두개 exp, main이 있다. 그중 exp|origin은 push까지 완료한 상태이다. push가 안되어있으면 exp하나만 남아아있음. 그래서 main에는 안 걸려있다.

origin : github를 의미한다.

main이 checkout인 상태에서 exp에 merge in current branch를 해주어서 main|origin가 나왔다.

origin|HEAD : github가 가르키고 있는 head를 알려준다.

git gui를 더블클릭하면 checkout이 된다.

git fetch : 파일을 가져오는것.
git merge : 파일 합치기

git revert

Pull & Request

참고하면 좋은 블로그

의미 : 우리가 작업한것을 코드를 검토해 달라.

branch를 하나만들고 commit and push.
=> 그 후에 깃허브 창 가보면 pull & request 만들기 가능

그 후 풀 리퀘스트 만듬. 그런데 pul & request 상태에서 서로 다른 branch에서 push 하면 conflict가 발생하면 바로 감지 가능. 원래는 merge할떄까지 모름. 충돌 계속 누적.

그때 resolve conflicts를 하면 해결 가능.

언제 pull request쓸 수 있는지 확인

브랜치(branch) : 저장소(repository) 내의 독립적인 관리영역
master 브랜치 : 저장소를 처음 생성할 때 만들어지는 브랜치
master : 해당 브랜치의 끝(최신 commit)을 참조하는 개체
HEAD : 어떤 commit을 가리키는 개체, HEAD가 이전 commit을 참조하면 Working directory의 내용이 이전 commit의 내용으로 변경됨

참고하면 좋은 사이트
협업 하는법

git graph

-분산 버전 관리 시스템-

main/origin || origin/Head 'commit name'

pull = fetch (땡겨오기) + merge(합치기)

git 구조

repository = local repository(computer) + remote repository(github)

loacl 저장소에 commit된 버전을 원격저장소로 push명령을 통해 넘길 수 있다.
remote repo는 많은 사람들과 공유하는 저장소로 사용되는 경우가 많다.
remote repo를 통해 협업하며 함께 개발해 나가는 것이다.

my local pc : push => remote repo
coworker pc : push => remote repo

remote

$ git remote add origin [github-repo-address.git]
이렇게 명령어를 사용하면 나의 로컬과 연결된다.
$ git remote -v : more info

push

push : 현재 프로젝트의 commited head 내용을 원격 저장소로 보내는 명령어.
$ git push
$ git push origin master


$ git add .
$ git commit -m 'date'
$ git push origin master

pull & fetch

원격 저장소에서 로컬 저장소로 소스를 가져오는 명령어 : pull, fetch
pull : 소스를 가져오고 현재 내 소스보다 더 최신 버전이라고 하면 업데이트 시킴(merge)
fetch : 소스를 가져오고 (No merge)
$ git fetch
$ git log : 가리키고 있는 위치 확인 가능

$ git diff : 어디가 변경되었는지 확인.

profile
AI와 수학, 일상 기록들

4개의 댓글

comment-user-thumbnail
2023년 3월 30일

git은 너무 어려운 것 같아요~

1개의 답글