github常用命令

github常用命令_第1张图片

github是优秀的代码托管和适合分支协作的分布式系统,由linux之父Linus花了两周时间完成,这才是传说中的大佬,为坚持开源精神继linux又带来了地球人的又一福音。

接下来记录一下常用命令。

CREATE(创建)

Clone an existing repository

 $ git clone ssh://[email protected]/repo.git

Create a new local repository

 $ git init

 

 LOCAL CHANGES(本地改变)

Changed files in your working directory

 $ git status

Changes to tracked files

 $ git diff

Add all current changes to the next commit

 $ git add .

Add some changes in  to the next commit

  $ git add -p 

Commit all local changes in tracked files

 $ git commit -a

Commit previously staged changes

 $ git commit

 

COMMIT HISTORY(提交历史记录)

Show all commits, starting with newest 

$ git log 

Show changes over time for a specific file 

$ git log -p 

show all history log

$git relog

BRANCHES(分支)

List all existing branches

 $ git branch -av

Switch HEAD branch

  $ git checkout 

Create a new branch based on your current HEAD

  $ git branch 

Delete a local branch

  $ git branch -d 

 

UPDATE & PUBLISH(更新,发布)

Download all changes from , but don‘t integrate into HEAD

  $ git fetch 

Download changes and directly merge/integrate into HEAD

  $ git pull  

Publish local changes on a remote

  $ git push  

Merge(合并)

Merge  into your current HEAD

  $ git merge 

undo(回退)

HEAD指向的版本就是当前版本,因此,Git允许我们在版本的历史之间穿梭,使用命令git reset --hard commit_id 
回退到上一个版本 
$ git reset --hard HEAD^

回退到上面第二个版本
$ git reset --hard HEAD^^

把文件在工作区的修改全部撤销
$ git checkout -- file(.代表所有文件,慎用,暂存区会覆盖所有工作区)
这里有两种情况: 
一种是文件自修改后还没有被放到暂存区,现在,撤销修改就回到和版本库一模一样的状态; 
一种是文件已经添加到暂存区后,又作了修改,现在,撤销修改就回到添加到暂存区后的状态。

最后推荐廖雪峰老师github教程,链接:https://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000

你可能感兴趣的:(java后端开发)