Git 리포지토리 필수 사항

8214 단어 repositorygit

이론



Git-repository는 git-branches 컬렉션입니다.

git-branch의 섹션/영역



모든 git-branch에는 기본적으로 5개의 섹션/드라이브/공간이 있습니다.
  • 작업 영역: 생성하거나 수정하는 모든 파일이 작업 영역에 자동으로 포함됨
  • 스테이징/인덱스 영역: 현재 변경 사항을 임시로 저장하는 영역입니다.
  • 은닉처: 임시 변경 사항 스택. 파일에서 지금 제거하고 나중에 포함하려는 변경 사항을 저장합니다. 둘 이상의 개발자가 동일한 브랜치에서 작업하고 이들 모두의 변경 사항을 차례로 포함하려는 경우 주로 사용해야 합니다
  • .
  • 커밋 영역: 커밋 스택을 포함합니다. 각 커밋은 커밋이 생성된 시점의 코드 스냅샷입니다. 변경 사항을 git에 영구적으로 저장합니다.
  • 원격 영역: Github 또는 Bitbucket과 같은 원격 서버에서 커밋 영역 백업/동기화

  • Working Area <-> Staging Area
    Working Area Staging Area -> Stash Area -> Working Area
    Staging Area <-> Commit Area
    Commit Area <-> Remote Area
    


    현실적인



    메모:


  • git --help를 사용하여 모든 git 명령을 참조하십시오.
  • 다음 코드에서 <file_path>.로 교체하여 모든 파일에 명령을 적용할 수 있습니다
  • .

    git-repository 생성 및 삭제




    git init # create first branch (master-branch) in current folder and move all your files in working area
    
    rm -rf .git  # remove all git drive / sections
    


    힘내 구성



    두 가지 git 구성이 있습니다 - 글로벌(새 리포지토리의 기본값) 및 로컬(현재 리포지토리의 경우)

    # use --global flag, to update gobal-configuation file
    git config -l   # list global and local git config
    git config -e  # update local git-config file which is present at ".git/config"
    git config user.name "John Doe" # update User/Author name
    git config user.email [email protected]
    git config core.editor "code --wait"    # set vs-code default editor for git
    git config core.editor "nano -w"       # set nano as default editor for git
    


    업무 공간




    git status # see which files / changes present in which area # file-names in red color are in working_area
    # file-names in green color are in staging_area
    
    git diff <file_path> # see changes present in working-area
    git restore <file_path>   # delete file-changes made working area
    git clean -f # delete all files in working area
    git clean -fd  # delete all files and directories in working area
    


    스테이징/인덱스 영역




    git diff --staged # see changes in present in staging_area
    git add <file_path>   # move changes (newly created files or modification in previous files) to staging area
    git restore --staged <file-path>   # move changes from staging_area to working_area
    


    은닉처




    git stash # move all changes from working and staging area to stash_area
    git stash list # list all blocks of temporariy changes
    git stash pop  # move most-recent block from stash_area to working_area ( position{0} )
    git stash clear # delete all blocks in stash
    


    커밋 영역




    git commit -m '<message>'     # move changes from staging_area to commit_area
    # <message> is short text giving information about changes made in the commit
    git commit --amend -m '<message>'  # move from staging_area to commit_area, but replace last-commit instead of creating new-commit
    git log  # view all commits in current branch
    git log --oneline # view all commits without description
    git log --oneline --graph --all  # view graphical representation of all branches
    git diff <commit_id> # view changes present in commit_id
    
    git revert <commit_ID> # remove all changes in given 'commit_ID'
    git reset HEAD~1  # delete last commit and move changes from last-commit to working-area
    # HEAD~2 will delete latest 2 commits, HEAD~3 will delete latest 3-commits and so on..
    


    외딴 지역




    git remote add <remote_area_name> <remote_area_url> # add connection to the remote_area
    # you can give any name you want to remote_area_name, devlopers normally use "origin" for their first / default remote_area
    git remote -v  # list currently set remote_area / servers names and their areas
    git remote remove <remote_area_name>   # remove connection with remote repository
    git push <remote_area_name> <branch-name> # copy changes in commit-area to remote_area
    git fetch <remote_area_name> <branch_name> # copy branch remote_area to commit_area
    git pull <remote_area_name> <branch_name> # merge remote branch to current branch
    git clone <remote_area_url> # copy git repository from remote server/area to current folder
    
    # for https-url
    git config --global credential.helper cache   # save github password so you don't have to type it again
    git config --global --unset credential.helper  # remove cached credentials
    


    지점 관리




    git branch <branch-name> # Create a new branch containing all git commits of current git-branch
    git checkout --orphan <name>  # create a fresh branch without commits from current-branch
    git branch -d <branch-name> # delete branch
    git branch -m <current-name> <new-name>  # Change branch name
    git checkout <branch-name> # move to another branch
    git branch --all  # list all local and remote branches
    
    git merge <branch-name> # merge branch with  <branch-name> to current branch
    git merge <branch-name> --allow-unrelated-histories  # merge branch whose git-history does not match with current branch, normally used to merge changes from another repository
    git merge --abort   # stop current merge process if there are conficts in merge, and you don't want to resolve them now
    


    힘내 태그




    git fetch --all --tags  # fetch all tags from remote
    git checkout tags/<version> -b <branch-name>  # switch to a tag and create bracnh for it
    

    좋은 웹페이지 즐겨찾기