zoukankan      html  css  js  c++  java
  • git提交到分支

    git checkout 

    grego@gregoo:mygo$ git checkout origin/test
    Note: checking out 'origin/test'.
    
    You are in 'detached HEAD' state. You can look around, make experimental
    changes and commit them, and you can discard any commits you make in this
    state without impacting any branches by performing another checkout.
    
    If you want to create a new branch to retain commits you create, you may
    do so (now or later) by using -b with the checkout command again. Example:
    
      git checkout -b <new-branch-name>
    
    HEAD is now at be427c9... Create README.md
    
    
    
    grego@gregoo:mygo$ git checkout master
    Switched to branch 'master'
    Your branch is up-to-date with 'origin/master'.
    
    
    
    grego@gregoo:mygo$ git branch
    * (HEAD detached from be427c9)
      master
      test
    grego@gregoo:mygo$ git branch -r
      origin/HEAD -> origin/master
      origin/master
      origin/test
    
    
    grego@gregoo:mygo$ git push origin HEAD:test
    Username for 'https://github.com': ningxin1718
    Password for 'https://ningxin1718@github.com': 
    Counting objects: 3, done.
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 313 bytes | 0 bytes/s, done.
    Total 3 (delta 0), reused 0 (delta 0)
    To https://github.com/ningxin1718/mygo.git
       be427c9..9a48c56  HEAD -> test

     git log 退出 按 q

    git回退

    git reset --hard <版本号> // 注意使用 --hard 参数会抛弃当前工作区的修改 // 使用 --soft 参数的话会回退到之前的版本,但是保留当前工作区的修改,可以重新提交
    
    为了覆盖掉远端的版本信息,使远端的仓库也回退到相应的版本,需要加上参数--force
    
    git push origin <分支名> --force
    

    git操作

    1. git add 添加 多余文件 
    这样的错误是由于, 有的时候 可能
    
    git add . (空格+ 点) 表示当前目录所有文件,不小心就会提交其他文件
    
    git add 如果添加了错误的文件的话
    
    撤销操作
    
    git status 先看一下add 中的文件 
    git reset HEAD 如果后面什么都不跟的话 就是上一次add 里面的全部撤销了 
    git reset HEAD XXX/XXX/XXX.java 就是对某个文件进行撤销了
    
    2. git commit 错误
    
    如果不小心 弄错了 git add后 , 又 git commit 了。 
    先使用 
    git log 查看节点 
    commit xxxxxxxxxxxxxxxxxxxxxxxxxx 
    Merge: 
    Author: 
    Date:
    
    然后 
    git reset commit_id
    
    over
    
    PS:还没有 push 也就是 repo upload 的时候
    
    git reset commit_id (回退到上一个 提交的节点 代码还是原来你修改的) 
    git reset –hard commit_id (回退到上一个commit节点, 代码也发生了改变,变成上一次的)
    
    3.如果要是 提交了以后,可以使用 git revert
    
    还原已经提交的修改 
    此次操作之前和之后的commit和history都会保留,并且把这次撤销作为一次最新的提交 
    git revert HEAD 撤销前一次 commit 
    git revert HEAD^ 撤销前前一次 commit 
    git revert commit-id (撤销指定的版本,撤销也会作为一次提交进行保存) 
    git revert是提交一个新的版本,将需要revert的版本的内容再反向修改回去,版本会递增,不影响之前提交的内容。
    

      

    …or create a new repository on the command line
    echo "# test" >> README.md
    git init
    git add README.md
    git commit -m "first commit"
    git remote add origin https://github.com/ningxin1718/test.git
    git push -u origin master
    …or push an existing repository from the command line
    git remote add origin https://github.com/ningxin1718/test.git
    git push -u origin master
    …or import code from another repository
    You can initialize this repository with code from a Subversion, Mercurial, or TFS project.
    step1,在本地新建分支
    git branch newbranch
    step2:把本地分支push到远程
    git push origin newbranch
    step3:切换到该分支
    git checkout newbranch
    step4:查看本地修改
    git status
    step5:添加本地修改
    git add .
    step6:commit修改
    git commit -m 'XXXX'
    
    

      

    拉取远程分支
    
    git fetch origin test
    git checkout -b test origin/test
    

      

  • 相关阅读:
    node md5
    Iptables入门教程
    centos 6.5 yum安装lnmp
    SSH日志位置
    【收藏】实战Nginx与PHP(FastCGI)的安装、配置与优化
    读《微博春晚背后的技术故事》笔记
    下载整个网页的方法,包括样式、图片、和js
    【收藏】下载Chrome商店插件的方法,万恶的gwd
    nginx变量
    【收藏】SSH原理与运用
  • 原文地址:https://www.cnblogs.com/ningxin18/p/9207229.html
Copyright © 2011-2022 走看看