zoukankan      html  css  js  c++  java
  • Git常用命令

    Create remote repo

    pwd:/Users/zhanglx/workspace/gittest/
    git init --bare --shared
    

    Clone repo from remote repo

    git clone /Users/zhanglx/workspace/gittest/
    

    Init a local git repo and add a remote

    This is equal to "Clone"

    mkdir myrepo
    cd myrepo/
    git init
    git remote add origin /Users/zhanglx/workspace/gittest/
    

    New branch and switch to this branch

    git branch test
    git checkout test
    

    Type git branch to check which branch you are working on.

    Add, modify, commit, reset and checkout history

    Git文件状态

    Git文件的状态分为untracked和tracked, untracked文件是指新建的文件,尚未被git管理起来。

    tracked又分为三种状态:

    已提交(committed),已修改(modified)和已暂存(staged)。已提交表示文件已被安全地保存在本地数据库中了;已修改表示修改了某个文件,但没有提交保存;已暂存表示把已修改的文件放在下次提交时要保存的清单中。

    Github

    git remote -v or git remote show origin 查看相关信息 git push origin master 将commit的代码,push到github上。 git pull origin master 将github上的代码,update到本地。

    Delete

    git delete file 然后commit的,将无法恢复。 rm file, 可以通过git checkout -- file进行恢复。 git rm --cached file,只是在缓存中删除,

    恢复更改的文件 git checkout — //未git add的文件

    git reset HEAD //已经git add的文件,可以用这个取消add,然后用上一条命令恢复

    Push master branch of locale repo to remote origin

    git push origin master

    Pull (if there are some conflicts, git will call git merge automatically)

    git pull origin master

    创建SSH key

    ssh-keygen
    生成的SSH key文件保存在中~/.ssh/id_rsa.pub
    

    添加SSH key到github

    接着拷贝.ssh/id_rsa.pub文件内的所以内容
    打开github帐号管理中的添加SSH key界面的步骤如下:
    1. 登录github
    2. 点击右上方的Accounting settings图标
    3. 选择 SSH key
    4. 点击 Add SSH key

    TAG
    $ git tag v1.4 -m ‘version 1.4′
    $ git tag
    $ git show v1.4

    $git checkout tag_name    //在当前分支上 取出 tag_name 的版本
    $git checkout -b branch_name tag_name //从 tag 创建一个分支,然后就和普通的 git 操作一样了

    作者:LessIsMorer

    Email:wenfeiexe@foxmail.com

    水平有限,文中错误不妥在所难免,欢迎批评指正。文章将不定期修改完善。转载请注明出处,谢谢!

  • 相关阅读:
    数学人眼中的湖北(五)
    数学人眼中的湖北
    范德蒙德恒等式
    日本高中数学的学习范围
    怎样搞数学竞赛
    单色三角形问题
    shell wait 和sleep 对比
    上传本地文件到github仓库
    windows2008服务器设置系统启动时程序自动运行
    小程序运行报错:errMsg: "request:fail url not in domain list"
  • 原文地址:https://www.cnblogs.com/gaowf/p/4317170.html
Copyright © 2011-2022 走看看