zdc253212956 发表于 2018-9-16 12:46:06

Git基础入门(七)Git撤销操作和远程仓库管理

  撤销操作:
  注意:Git的有些撤消操作是不可逆的。 这是在使用Git的过程中,会因为操作失误而导致之前的工作丢失的少有的几个地方之一
  取消暂存的文件
  git add a.py b.py
  git status
  On branch master
  Changes to be committed:
  (use "git reset HEAD ..." to unstage)         #提示如何撤销
  modified:   a.py
  modified:   b.py
  git reset HEAD b.py                                       #取消暂存b.py
  Unstaged changes after reset:
  Mb.py
  git status
  On branch master
  Changes to be committed:
  (use "git reset HEAD ..." to unstage)
  modified:   a.py
  Changes not staged for commit:
  (use "git add ..." to update what will be committed)
  (use "git checkout -- ..." to discard changes in working directory)         #提示可以撤销对文件的修改
  modified:   b.py
  撤消对文件的修改
  git checkout b.py
  git status
  On branch master
  Changes to be committed:
  (use "git reset HEAD ..." to unstage)
  modified:   a.py
  git checkout -- 是一个危险的命令,如果执行了这个命令你对那个文件做的任何修改都会消失
  远程仓库:
  远程仓库是指托管在因特网或其他网络中的你的项目的版本库,远程仓库可以有多个,通常有些仓库对你只读,有些则可以读写
  管理远程仓库包括了解如何添加远程仓库、移除远程仓库、管理不同的远程分支并定义它们是否被跟踪等等
  查看远程仓库
  git remote            #查看当前所有的远程仓库
  origin            #origin 是Git给你克隆的仓库服务器的默认名字
  -v选项,显示远程仓库的简写与其对应的URL
  git remote -v
  originhttps://github.com/libgit2/libgit2 (fetch)
  originhttps://github.com/libgit2/libgit2 (push)
  添加远程仓库
  git remote add            #添加一个新的远程Git仓库,同时指定一个简写
  git remote add test https://github.com/huyuan1999/17-10-22.git          #添加远程仓库
  git remote -v
  originhttps://github.com/libgit2/libgit2 (fetch)
  originhttps://github.com/libgit2/libgit2 (push)
  testhttps://github.com/huyuan1999/17-10-22.git (fetch)
  testhttps://github.com/huyuan1999/17-10-22.git (push)
  现在可以在命令行中使用test来代替整个URL
  git fetch test          #拉取远程仓库中的信息(本地工作目录中没有的信息)
  从远程仓库中抓取与拉取
  git fetch    #拉取远程仓库中的数据(不会自动合并分支)
  如果使用clone命令克隆了一个仓库,并将其添加为远程仓库默认以origin为简写。所以git fetch origin会抓取克隆后新推送的所有数据
  git pull       #自动的抓取然后合并远程分支到当前分支
  默认情况下git clone会自动设置本地master分支跟踪克隆的远程仓库master分支,运行git pull通常会从克隆的服务器上抓取数据并自动尝试合并到当前分支
  推送到远程仓库
  git push             #推送指定分支到服务器中
  git push test master            #git默认使用github做为远程仓库服务器,如果想要推送到远程仓库则需要有对应的账号和密码
  查看远程仓库
  git remote show test
  * remote test                               #本地简写
  Fetch URL: https://github.com/huyuan1999/17-10-22.git
  PushURL: https://github.com/huyuan1999/17-10-22.git
  HEAD branch: master                     #处于的分支
  Remote branch:
  master tracked                        #掌握跟踪
  Local ref configured for 'git push':
  master pushes to master (up to date)
  远程仓库的移除与重命名
  git remote rename test hu               #重命名
  git remote
  origin
  hu
  git remote rm hu                        #移除
  git remote
  origin

页: [1]
查看完整版本: Git基础入门(七)Git撤销操作和远程仓库管理