• Git使用


    Git Command


    • Init a repository
    mkdir git-learning
    cd git-learning
    git init
    ~ Initialized empty Git repository in S:/CODE/git-learning/.git/
    
    • Add and commit
    git add read.md
    git add -p read.md //选择提交一部分
    git commit -m "feat: add a readme file"
    
    • Repository status
    git status
    git diff <filename>
    git diff HEAD -- <filename>  //查看工作区和版本库最新版本区别
    
    • Git log
    git log    //显示从最近到最远的提交日志
    git log --pretty=oneline
    git reflog
    
    • Reset head
    git reset --hard HEAD~<version number>
    git reset --hard 4431212
    //--hard和--soft的区别
    //git reset 可以回退版本,也可以吧暂存区的修改回退到工作区
    
    • Restore changes
    //文件没有add到暂存区之前
    1 git checkout -- <filename>
    2 git restore <filename>
    //文件add到暂存区
    1 git reset HEAD <filename>
      git checkout -- <filename>
    2 git restore --staged <filename>
      git restore <filename>
    
    • View branch
    git branch //查看当前本地分支
    git branch -r //查看远程分支
    git branch -a //查看所有分支
    
    • Switch branch
    git checkout dev
    git switch dev
    
    • Create branch
    git checkout -b dev  //创建并切换,相当于git branch dev, git checkout dev
    git switch -c dev   //同上面的命令
    
    • Merge branch to master
    git checkout master
    git merge dev  //将dev合并到master
    git merge --no-ff -m <commit message> <branch> //合并分支到当前分支并增加一个commit
    
    • Delete branch
    git branch -d dev
    git branch -D dev //强制删除
    
    • View branch merge log
    git log --graph --pretty=oneline --abbrev-commit
    
    • Stash
    git stash   //当前还没add的修改保存到stash
    git stash list  //查看所有stash列表
    git stash apply stash@{0} //还原stash的修改
    git stash show -p         //查看stash详细修改
    
    • Cherry-pick
    git cherry-pick <commit-id>  //将其他分支的commit复制到当前分支
    
    • Track remote repository
    git remote add origin git@github.com:dshipeng/git-learning.git
    //origin是远程库的名字,这是git的默认叫法
    git push -u origin master
    //将本地master分支推送到远程,第一次推送加上-u参数,git不但会把本地的master分支内容推送到远程新的master分支,还会将两个分支关联,以后推送就可以简化命令了git push origin master
    
    • Push remote repository
    git push origin <local branch>:<remote branch>
    git push  //通常可省略
    
    • View remote repository
    git remote
    git remote -v
    
    • Clone remote repository
    git clone git@github.com:dshipeng/gt-learning.git
    
    • Checkout remote branch
    git checkout -b dev oorigin/dev  //将远程分支拉取到本地
    git branch --set-upstream-to=origin/dev dev //建立本地分支与远程分支的关联
    git push --set-upstream origin <branch>
    
    • Rebase branch
    git rebase
    git rebase -i         //交互式处理commit
    git rebase --continue //解决冲突后执行
    git rebase --abort    //放弃rebase
    git rebase --skip     //将引起冲突的commits丢弃(慎用!)
    
    • Tag
    git tag v1.0 <commit-id>
    git tag -a v0.1 -m <commet> <commit-id>
    git tag   //查看所有标签
    git show v1.0
    git tag -d v1.0 //删除
    git push origin v1.0 //push remote
    git push origin :refs/tags/v1.0 //删除远程标签
    
    • Refresh remote branch list
    git remote update origin -p
    
    • Edit branch commits
    git rebase -i <commit-id>
    git rebase --continue
    git push --force
    
  • 相关阅读:
    HDOJ_ACM_超级楼梯
    HDOJ_ACM_下沙的沙子有几粒?
    杭电_ACM_How Many Trees
    HDOJ_ACM_Tiling_easy version
    HDOJ_ACM_母牛的故事
    HDOJ_ACM_小兔的棋盘
    HDOJ_ACM_一只小蜜蜂
    杭电_ACM_Count the Trees
    HDOJ_ACM_折线分割平面
    Sun Solaris下JAVA以及JSP开发环境的配制小记
  • 原文地址:https://www.cnblogs.com/prelude1214/p/13986176.html
Copyright © 2020-2023  润新知