[Git]常用命令

Git 常用命令

查看提交历史

git log  
--pretty
git log --pretty=oneline -n
git log --pretty=format:"%h %s" --graph

放弃更改

  1. 当文件未被放入暂存区

    git checkout -- <filepath>
    git checkout -- .    
    
  2. 文件已经放入暂存区

     git reset HEAD <filepath>
     git reset HEAD .    
    
  3. 文件已经提交commit

    git reset --hard <commitid>
    git reset --hard HEAD^
    

新建分支

git branch <name>
git checkout <name>

# 或者新建并切换:
git checkout -b <name>

变基

# 假设当前工作分支为branch2,要以branch1为基础,提交代码
git rebase branch1
git checkout branch1
git merge branch2
git push
...
posted @ 2019-12-03 10:22  Waters37  阅读(60)  评论(0)    收藏  举报