Git

头像
Lycheeee
    阅读 2 分钟
    1

    Installation
    see guide

    Create and Add
    Give git authority to control dir rep

    mkdir rep
    cd rep
    git init

    put f1.txt,f2.txt into rep

    git add f1.txt f2.txt
    git commit -m "add 2 files"

    to check the current status & see the differences & check version log (commit history)

    git status
    git diff f1.txt
    git log

    use git log --pretty=oneline to compress each log to one line

    Rolling back & delete
    to last, second last, 100 last version, exact version with vid

    git reset --hard HEAD^, HEAD^^, HEAD~100, vid

    use git reflog to see the vid of previous changes (command history)

    to revoke the change (did not add to the stage)

    git checkout -- f1.txt

    for already adding to the stage

    git reset HEAD f1.txt
    

    to delete the file

    git rm f1.txt
    git commit
    

    Connect to remote repository
    set the name of remote rep as origin and push from local to remote, add para -u for the first time in order to link the local and remote

    git remote add origin git@github.com:GITHUBNAME/learngit.git
    git push -u origin master

    clone from remote to local

    git clone git@github.com:GITHUBNAME/learngit.git
    

    create a branch nb and point to it

    git checkout -b nb

    to create & point separately

    git branch nb
    git checkout nb

    use git branch to see current branch, git merge nb to merge nb to master and abandon the branch, git merge --no-ff to merge and keep the branch simultaneously

    Fixing Bug
    to fix a bug on master branch, store the current work status in stash

    git stash
    git checkout master
    git checkout -b tmp_branch

    after fixing

    git branch -d tmp_branch
    git stash pop
    

    Tagging
    tag current version, previous version, delete tag

    git tag v1.0, git tag v0.9 vid, git tag -d v0.9

    delete remote tag, first git tag -d v0.9, then git push origin :refs/tags/v0.9


    Lycheeee
    0 声望1 粉丝

    下一篇 »
    SVD