git教程

Git 与 SVN 区别点:

  • 1、Git 是分布式的,SVN 不是:这是 Git 和其它非分布式的版本控制系统,例如 SVN,CVS 等,最核心的区别。

  • 2、Git 把内容按元数据方式存储,而 SVN 是按文件:所有的资源控制系统都是把文件的元信息隐藏在一个类似 .svn、.cvs 等的文件夹里。

  • 3、Git 分支和 SVN 的分支不同:分支在 SVN 中一点都不特别,其实它就是版本库中的另外一个目录。

  • 4、Git 没有一个全局的版本号,而 SVN 有:目前为止这是跟 SVN 相比 Git 缺少的最大的一个特征。

  • 5、Git 的内容完整性要优于 SVN:Git 的内容存储使用的是 SHA-1 哈希算法。这能确保代码内容的完整性,确保在遇到磁盘故障和网络问题时降低对版本库的破坏。

  • 一般工作流程如下:

  • 克隆 Git 资源作为工作目录。
  • 在克隆的资源上添加或修改文件。
  • 如果其他人修改了,你可以更新资源。
  • 在提交前查看修改。
  • 提交修改。
  • 在修改完成后,如果发现错误,可以撤回提交并再次修改并提交。
  • git clone

    我们使用 git clone 从现有 Git 仓库中拷贝项目(类似 svn checkout)。

  • lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt
    $ git clone https://github.com/linjiayang/mine.git
    Cloning into 'mine'...
    warning: You appear to have cloned an empty repository.
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt
    $ ls
    mine/
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt
    $ ll
    total 0
    drwxr-xr-x 1 lin 197121 0 11月 30 11:24 mine/
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt
    $ ls -a
    ./  ../  mine/
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt
    $ ls -l
    total 0
    drwxr-xr-x 1 lin 197121 0 11月 30 11:24 mine/
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt
    $ cd mine
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt/mine (master)
    $ ll
    total 0
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt/mine (master)
    $ touch tt.txt
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt/mine (master)
    $ vim tt.txt
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt/mine (master)
    $ git status
    On branch master
    
    No commits yet
    
    Untracked files:
      (use "git add <file>..." to include in what will be committed)
    
            tt.txt
    
    nothing added to commit but untracked files present (use "git add" to track)
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt/mine (master)
    $ git add tt.txt
    warning: LF will be replaced by CRLF in tt.txt.
    The file will have its original line endings in your working directory.
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt/mine (master)
    $ git status
    On branch master
    
    No commits yet
    
    Changes to be committed:
      (use "git rm --cached <file>..." to unstage)
    
            new file:   tt.txt
    
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt/mine (master)
    $ git push
    error: src refspec refs/heads/master does not match any.
    error: failed to push some refs to 'https://github.com/linjiayang/mine.git'
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt/mine (master)
    $ git commit -m "first"
    [master (root-commit) c808c02] first
     1 file changed, 1 insertion(+)
     create mode 100644 tt.txt
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt/mine (master)
    $ git status
    On branch master
    Your branch is based on 'origin/master', but the upstream is gone.
      (use "git branch --unset-upstream" to fixup)
    
    nothing to commit, working tree clean
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt/mine (master)
    $ git push
    Counting objects: 3, done.
    Writing objects: 100% (3/3), 202 bytes | 50.00 KiB/s, done.
    Total 3 (delta 0), reused 0 (delta 0)
    To https://github.com/linjiayang/mine.git
     * [new branch]      master -> master
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt/mine (master)
    $ git pull
    Already up to date.
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt/mine (master)
    $ git branch
    * master
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt/mine (master)
    $ git branch -a
    * master
      remotes/origin/master
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt/mine (master)
    $ git checkout -b branch1
    Switched to a new branch 'branch1'
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt/mine (branch1)
    $ git branch
    * branch1
      master
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt/mine (branch1)
    $ ll
    total 1
    -rw-r--r-- 1 lin 197121 16 11月 30 11:35 tt.txt
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt/mine (branch1)
    $ vim tt.txt
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt/mine (branch1)
    $ cat tt.txt
    ttttttttttttttdfdfdfdfdft
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt/mine (branch1)
    $ git add tt.txt
    warning: LF will be replaced by CRLF in tt.txt.
    The file will have its original line endings in your working directory.
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt/mine (branch1)
    $ git commit -m "second" tt.txt
    warning: LF will be replaced by CRLF in tt.txt.
    The file will have its original line endings in your working directory.
    [branch1 8841d5f] second
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt/mine (branch1)
    $ git push
    fatal: The current branch branch1 has no upstream branch.
    To push the current branch and set the remote as upstream, use
    
        git push --set-upstream origin branch1
    
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt/mine (branch1)
    $ ^C
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt/mine (branch1)
    $ git push --set-upstream origin branch1
    
    Counting objects: 3, done.
    Writing objects: 100% (3/3), 236 bytes | 33.00 KiB/s, done.
    Total 3 (delta 0), reused 0 (delta 0)
    remote:
    remote: Create a pull request for 'branch1' on GitHub by visiting:
    remote:      https://github.com/linjiayang/mine/pull/new/branch1
    remote:
    To https://github.com/linjiayang/mine.git
     * [new branch]      branch1 -> branch1
    Branch 'branch1' set up to track remote branch 'branch1' from 'origin'.
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt/mine (branch1)
    $
    
    lin@DESKTOP-7GHMGNI MINGW64 ~/Desktop/package of test/【赠】软件测试各种模板文档/gitt/mine (branch1)
    $git merge branch1
    

     

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值