Day3|【Git】终端机常用基本指令 - Mac 作业系统为主

学习 Git 时,常常都是在终端机(Terminal)操作,虽然现在有很多图形介面工具(GUI,Graphic User Interface),如:SourceTree、GitHub Desktop,在操作上更直觉性。但是能够了解 Git 指令的操作原理,在遇到问题时可以试着使用指令解决。

以下是常见的系统指令

https://ithelp.ithome.com.tw/upload/images/20210917/20141010mGWR8TjAIW.png

常用指令整理

以下操作指令皆以 Mac 作业系统为主

$ 符号不需要打上去,这只是代表需要手动输入的意思。

目录切换及显示 cd

$ cd [目录名称] # 切换到某目录

进入对应位置後,在正确的目录下才能进行各种版本控制。
https://ithelp.ithome.com.tw/upload/images/20210914/20141010xcBMX5SPbW.png
https://ithelp.ithome.com.tw/upload/images/20210914/20141010RxBvhqUKNa.png

档案列表 $ ls -al

$ cd .. # 切换回到上一层
$ ls -al # 显示完整的档案列表(包含隐藏项目)

ls 指令 - 列出目前目录的所有档案及目录
-al参数 - a 代表小数点开头的档案也会一同显示。l 表示完整档案的权限、拥有者以及建立、修改时间。
https://ithelp.ithome.com.tw/upload/images/20210914/20141010mFi1YfdCR2.png
https://ithelp.ithome.com.tw/upload/images/20210914/20141010R0cyEkAdIu.png

建立档案、目录 touch mkdir

$ touch  project.html # 新建一个 project.html 档案
//touch + [档案名称] - 建立档案

https://ithelp.ithome.com.tw/upload/images/20210914/20141010TymXTOcJoX.png
https://ithelp.ithome.com.tw/upload/images/20210914/20141010J9XOHsNeMX.png
建立一个 project.html 的档案。

补充:如果原来已经存在这个档案,那麽只会改变档案最後修改时间,而不会改变档案的内容
https://ithelp.ithome.com.tw/upload/images/20210914/20141010nyo2TTWzK0.png
https://ithelp.ithome.com.tw/upload/images/20210914/20141010amlpDB0lCm.png

--

$ mkdir new # 新建一个 new 目录
//mkdir + [档案名称] - 建立目录

https://ithelp.ithome.com.tw/upload/images/20210914/20141010J9s3V4se1o.png
https://ithelp.ithome.com.tw/upload/images/20210914/20141010NoYDsuBpdh.png
在目前的目录新增一个 new 目录。

补充:如果原来已经存在这个工作目录,那麽会告诉你此工作目录已存在
https://ithelp.ithome.com.tw/upload/images/20210914/20141010XVK33wLASU.png

档案操作 cp mv rm rm*

  • cp 复制

    $ cp index.html cat.html  # 复制一个与 index.html 相同内容的 cat.html 档案
    //cp + [欲改变的档案名称] + [改变後的档案名称]
    

    https://ithelp.ithome.com.tw/upload/images/20210914/20141010GKvFv6BTeQ.png
    https://ithelp.ithome.com.tw/upload/images/20210914/20141010mcKt0Tw0gJ.png
    将 index.html 档案 复制 一份名为 cat.html 的档案。
    https://ithelp.ithome.com.tw/upload/images/20210914/20141010qEeZJs0jzX.png
    https://ithelp.ithome.com.tw/upload/images/20210914/20141010b4kXvBVOSw.png

  • mv 更改档案名字

    $ mv cat.html dog.html  # 将 cat.html 档案更名为 dog.html
    //mv + [原档案名称] + [更改後的档案名称]
    

    https://ithelp.ithome.com.tw/upload/images/20210914/201410101ysEy51RSM.png
    将 cat.html 档案 更改档名 为 dog.html 的档案。

    https://ithelp.ithome.com.tw/upload/images/20210914/20141010k5QXbz2RXK.pnghttps://ithelp.ithome.com.tw/upload/images/20210914/20141010mo6BzibEyZ.png

  • rm 删除

    $ rm dog.html  # 将 dog.html 档案删除
    //rm + [想删除的档案名称]
    

    https://ithelp.ithome.com.tw/upload/images/20210914/20141010B2Oz8QouWH.png
    https://ithelp.ithome.com.tw/upload/images/20210914/20141010RQZhG4oekl.png
    将 index.html 档案 删除

  • rm * 删除所有档案

    $ rm *  # 将所有档案删除
    

    https://ithelp.ithome.com.tw/upload/images/20210914/20141010vDPx8UfmsJ.png
    https://ithelp.ithome.com.tw/upload/images/20210914/20141010LDq8YVSaJE.png

    补充:
    $ rm *.html - rm + [ * . 想删除的档案类型 ]
    将副档名为 .html 的 所有档案全部删除


熟能生巧,多次练习

一开始或许看到这麽多的指令会感觉到复杂与害怕,而对指令退避三舍。但是会害怕是因为对於这件事物我们不了解、不熟悉,才会产生的感觉,所以只要勇敢面对、仔细观察,这些指令都与动作的原文相似,只要多次的练习就会有一定的熟悉度,对这些指令会更有印象,操作也会愈来愈熟练。


<<:  Graph-Tree: uva 615 Is It A Tree?

>>:  [Day03] Flutter GetX equatable

[Day 28] API前後端串接

API前後端串接 今日学习目标 API 前後端串接 建立一个鸢尾花朵分类器的网页 API URL 采...

模型的内容05 def main()

接着我们说明optimizer设定 。 首先,我们先得知道 training and validat...

Day28 简易小键盘小实作3

接着则是加法运算,按下加数後,label变空字串,运算.add,是否值行运算(是),先前的数字为萤幕...

知识工作者的管理

在上一篇我分享过我对「工作的意义与价值」的观察。读过後,你该不难理解为何当年 Jack Welch...

初探网路安全(二):密码怎麽被「试」出来的

每一年都可以看到新闻在报资安公司所统计出来的年度最烂密码,诸如以下 123456789 pictur...