看完不会Git命令行我跪搓板(5)

  • 撤销未添加到暂存区的修改

    [原创文章:www.11jj.com]

  • fukqdembp:TestGit fukq$ git status
    On branch master
    Your branch is up to date with "origin/master".

    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   TestGit.md

    no changes added to commit (use "git add" and/or "git commit -a")
    [本文来自:www.11jj.com]

    说明:discard changes - 放弃修改:的提示为 "git checkout -- <file>..."

    fukqdembp:TestGit fukq$ git checkout -- TestGit.md
    fukqdembp:TestGit fukq$ git status
    On branch master
    Your branch is up to date with "origin/master".

    nothing to commit, working tree clean

  • 撤销已添加到暂存区的修改:

  • fukqdembp:TestGit fukq$ git add TestGit.md
    fukqdembp:TestGit fukq$ git status
    On branch master
    Your branch is up to date with "origin/master".

    Changes to be committed:
      (use "git reset HEAD <file>..." to unstage)

        modified:   TestGit.md

    说明:to unstage - 不暂存的提示为 "git reset HEAD <file>..."

    fukqdembp:TestGit fukq$ git reset HEAD TestGit.md
    Unstaged changes after reset:
    M   TestGit.md
    fukqdembp:TestGit fukq$ git status
    On branch master
    Your branch is up to date with "origin/master".

    Changes not staged for commit:
      (use "git add <file>..." to update what will be committed)
      (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   TestGit.md

    no changes added to commit (use "git add" and/or "git commit -a")
    fukqdembp:TestGit fukq$

    删除相关操作

  • 删除文件后的Git同步操作

  • fukqdembp:TestGit fukq$ ls
    LICENSE     README.md   TestGit.md  TestGit.txt
    fukqdembp:TestGit fukq$ rm TestGit.txt
    fukqdembp:TestGit fukq$ git status
    On branch master
    Your branch is ahead of "origin/master" by 1 commit.
      (use "git push" to publish your local commits)

    Changes not staged for commit:
      (use "git add/rm <file>..." to update what will be committed)
      (use "git checkout -- <file>..." to discard changes in working directory)

        deleted:    TestGit.txt

    no changes added to commit (use "git add" and/or "git commit -a")
    fukqdembp:TestGit fukq$ git rm TestGit.txt
    rm "TestGit.txt"
    fukqdembp:TestGit fukq$ git commit TestGit.txt -m "删除TestGit.txt文件"
    [master 7075b5f] 删除TestGit.txt文件
     1 file changed, 1 deletion(-)
     delete mode 100644 TestGit.txt
    fukqdembp:TestGit fukq$ git status
    On branch master
    Your branch is ahead of "origin/master" by 2 commits.
      (use "git push" to publish your local commits)

    nothing to commit, working tree clean
    fukqdembp:TestGit fukq$ ls
    LICENSE     README.md   TestGit.md

    说明:
    ① rm TestGit.txt
    ② git rm TestGit.txt
    ③ git commit TestGit.txt -m "删除TestGit.txt文件"

  • 删除文件后的恢复文件操作

  • fukqdembp:TestGit fukq$ rm TestGit.txt
    fukqdembp:TestGit fukq$ git status
    On branch master
    Your branch is ahead of "origin/master" by 3 commits.
      (use "git push" to publish your local commits)

    Changes not staged for commit:
      (use "git add/rm <file>..." to update what will be committed)
      (use "git checkout -- <file>..." to discard changes in working directory)

        deleted:    TestGit.txt

    no changes added to commit (use "git add" and/or "git commit -a")
    fukqdembp:TestGit fukq$ git checkout -- TestGit.txt
    fukqdembp:TestGit fukq$ ls
    LICENSE     README.md   TestGit.md  TestGit.txt

    说明:$ git checkout --TestGit.txt 既可以对未添加到暂存区的修改操作进行恢复,也可以对已删除的文件进行恢复。

    远程仓库

  • 关联远程仓库

  • $git remote add origin git@github.com:OnlyYouMyLove/TestGit.git

    说明:
    ① 组成 -- git remote add + 自定义仓库命名 + 仓库ssh地址
    ② git init 初始化仓库以后需要进行 git remote操作,实现本地和远程仓库的绑定,这才能算是完整创建本地仓库。

  • 第一次推送本地仓库内容到远程仓库

  • $git push -u origin master

    说明:
    ① -u 参数的添加可以让本地仓库和远程仓库进行绑定
    ② 如果报以下错,意思是缺少权限--本地生成ssh,添加到github的ssh列表即可:

    $git push -u origin master
    Warning: Permanently added the RSA host key for IP address "xxx.xx.xxx.xxx" to the list of known hosts.
    Permission denied (publickey).
    fatal: Could not read from remote repository.

    Please make sure you have the correct access rights
    and the repository exists.

    ③ 如果报以下错,输入yes即可:

    自媒体 微信号:11jj 扫描二维码关注公众号
    爱八卦,爱爆料。

    小编推荐

    1. 1

      @全体师生 防灾减灾宣传周主题海报来了

      本年5月12日是第16个全国防灾减灾日主题是“人人讲平安、个个会应急——出力提拔下层防灾避险能力”5月11日至17日为防灾减灾宣传周国度防灾减灾

    2. 2

      名单出炉!莆田首支霹雳舞市级集训队名单确定

      近日由莆田市体育局荔城区文化体育和旅行局作为指导单元单子莆田市体育跳舞活动协会主办莆田市体育跳舞活动协会街舞专业委员会协办的“奔驰

    3. 3

      你的【福利】即将到账

      叮!我预备了【京东卡】要给你!你的【福利】即将到账!叮!你有一张【京东卡】待查收天色逐渐转暖,属于炎天的康乐就要回来了!大排档里黏

    4. 4

      优秀护士工作总结(优秀护士工作总结自参加工作以来)

      大家好,小丽今天来为大家解答优秀护士工作总结以下问题,优秀护士工作总结自参加工作以来很多人还不知道,现在让我们一起来看看吧!1、轻基

    5. 5

      《健康中国观察》封面文章,介绍苏州经验!

      《健康中国视察》2024年4月刊登载了题为《共建共享 健康姑苏——中国式现代化配景下的健康城市索求与实践》的封面文章聚焦姑苏健康城市扶植经

    6. 6

      送红包1314是什么意思(红包1314是多少钱)

      大家好,小乐今天来为大家解答送红包1314是什么意思以下问题,红包1314是多少钱很多人还不知道,现在让我们一起来看看吧!1、1314,即一生一世谐

    7. 7

      她打翻了上帝的水彩盒!太美了!

      Anna Armona 乌克兰艺术家她的水彩作品唯美、抽象且具有诗意那种布满着梦幻的色彩,灿烂斑斓,使人感受赞叹、震撼与晕眩!春:夏秋冬图文起原收

    8. 8

      辞退无固定期限合同员工的赔偿(辞退无固定期限合同员工的赔偿最高)

      大家好,小娟今天来为大家解答辞退无固定期限合同员工的赔偿以下问题,辞退无固定期限合同员工的赔偿最高很多人还不知道,现在让我们一起来

    Copyright 2024.依依自媒体,让大家了解更多图文资讯!