• Git Sheet


    Create

    Clone an existing repository

    git clone ssh://user@domain.tld/repo.git

    Clone an existing repository and all its sub-modules recursively

    git clone --recursive ssh://user@domain.tld/repo.git

    Create a new local repository

    git init

    Local Changes

    List changed files in your working directory

    git status 

    List changes to tracked files

    git diff

    Add all current changes to the next commit

    git add .

    Add some changes to the next commit

    git add -p fileName

    Commit all local changes in tracked files

    git commit -a

    Commit previously staged changes

    git commit

    Change the last commit

    git commit --amend

    Note: You shouldn't amend published commits!

    Commit History

    Show all commits

    git log

    Show changes over time for a specific file

    git log -p fileName

    Show changes over time for a specific committer

    git log --author=committerName

    Note: committerName is a pattern, so Ed will match Edward Smith. Quotes are optional if the pattern doesn't contain spaces.

    Who changed what and when in file

    git blame fileName

    Store changes temporarily

    git stash

    Remove and apply stashed changes

    git stash pop

    Branches & Tags

    List all existing branches

    git branch

    Switch HEAD branch

    git checkout branchName

    Create a new branch based on your current HEAD

    git branch branchName

    Create a new tracking branch based on a remote branch

    git branch --track newBranchName remoteBranchName

    Delete a local branch

    git branch -d branchName

    Delete a remote branch

    git push origin --delete branchName

    Tag the current commit

    git tag tagName

    Update & Publish

    List all currently configured remotes

    git remote -v

    Show information about a remote

    git remote show remoteName

    Add new remote repository

    git remote add remoteName url

    Download all changes from remote, but don't merge into HEAD

    git fetch remoteName

    Download all changes from remote, but don't merge into HEAD and clean up deleted branches from origin

    git fetch -p remoteName

    Download changes and directly merge into HEAD

    git pull remoteName branchName

    Publish local changes on a remote

    git push remoteName branchName

    Track a remote repository

    git remote add --track remoteBranchName remoteName url

    Publish your tags

    git push --tags

    Merge

    Merge branch into your current HEAD

    git merge branchName

    Rebase your current HEAD onto branch

    git rebase branchName

    Note: You shouldn't rebase published commits!

    Rebase

    Abort a rebase

    git rebase --abort

    Continue a rebase after resolving conflicts

    git rebase --continue

    Resolve conflicts using your configured merge tool

    git mergetool

    Manually resolve conflicts using your editor and mark file as resolved

    git add resolvedFileName
    git rm resolvedFileName

    Undo

    Discard all local changes in your working directory

    git reset --hard HEAD

    Discard local changes in a specific file

    git checkout HEAD fileName

    Revert a commit by providing a new commit with contrary changes

    git revert commitId

    Restore a specific file from a previous commit

    git checkout commitId fileName

    Reset your HEAD pointer to a previous commit

    Discarding local changes

    git reset --hard commitId

    Preserving all changes as unstaged changes

    git reset commitId

    Preserving uncommitted local changes

    git reset --keep commitId
  • 相关阅读:
    IO
    File
    jdbc
    HashMap
    网络通信
    lambda
    Queue
    反射
    Stack
    AC自动机题目选讲
  • 原文地址:https://www.cnblogs.com/xwoder/p/4495799.html
Copyright © 2020-2023  润新知