github常用命令

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

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

CREATE(创建)

Clone an existing repository

 $ git clone ssh://user@domain.com/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 <file> to the next commit

  $ git add -p <file>

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 <file>

show all history log

$git relog

BRANCHES(分支)

List all existing branches

 $ git branch -av

Switch HEAD branch

  $ git checkout <branch>

Create a new branch based on your current HEAD

  $ git branch <new-branch>

Delete a local branch

  $ git branch -d <branch>

 

UPDATE & PUBLISH(更新,发布)

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

  $ git fetch <remote>

Download changes and directly merge/integrate into HEAD

  $ git pull <remote> <branch>

Publish local changes on a remote

  $ git push <remote> <branch>

Merge(合并)

Merge <branch> into your current HEAD

  $ git merge <branch>

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

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值