git简明使用教程

整个过程分三步:

  • 第一步:整理文件
    • # 新建干净的目录
    • mkdir /option-master/option-monitor
    • # 只把核心文件拷进去
    • cp option_monitor_tqsdk_20260522b.py option-monitor/
    • cp gen_atm.py option-monitor/
    • cp kqCode.csv option-monitor/
    • cp requirements.txt option-monitor/
    • cp README.md option-monitor/
    • 排除的东西:option_*.csv(几十MB的监控数据)、.bak、复制.csv、图片、instock/
    • 子项目等。
  • 第二步:创建 .gitignore
    • 告诉 Git 哪些文件不要管:
    • cd /option-master/option-monitor
    • cat > .gitignore << ‘EOF’
    • .bak option_.csv
    • kqdata.csv
    • kq_atm.csv
    • pycache/
    • EOF
  • 第三步:初始化并提交
    • git init # 创建空仓库(一瞬间,不联网)
    • git config user.name “option-monitor” # 署名
    • git config user.email “monitor@local”
    • git add .gitignore # 先加 gitignore
    • git add *.py *.csv *.txt *.md # 加核心文件
    • git commit -m “初始版本” # 提交到本地仓库

关键点:git init 只是在当前目录创建了一个隐藏的 .git
文件夹,完全不联网。联网只在 git push 到 GitHub 时才需要。

# ── 联网(以后配了 GitHub 再用)──
git remote add origin https://github.com/xxx/xxx.git
git push -u origin master

Git 本身

Git 是一个独立的版本控制工具,Windows 需要手动安装:

  1. 去 https://git-scm.com/download/win 下载安装
  2. 安装后会得到 Git Bash(一个终端)和 git 命令 PyCharm 里的 Git PyCharm 内置了 Git 的图形界面,但底层还是调用你系统上安装的 Git: PyCharm → 调用系统 Git → 读写 .git 仓库 所以必须先装好 Git for Windows,PyCharm 才能用。 Windows 上的三种用法 ┌────────────────┬───────────────────────────────────────────────────────┐
    │ 方式 │ 怎么操作 │
    ├────────────────┼───────────────────────────────────────────────────────┤
    │ PyCharm 里 │ Ctrl+K 提交、Ctrl+Shift+K 推送、底部 Git 标签看历史 │
    ├────────────────┼───────────────────────────────────────────────────────┤
    │ Git Bash │ 打开后和 Linux 终端一样,git add / git commit │
    ├────────────────┼───────────────────────────────────────────────────────┤
    │ CMD/PowerShell │ 安装时选 “Git from command line”,就能在 cmd 里用 git │
    └────────────────┴───────────────────────────────────────────────────────┘
  3. Windows 和 Linux 共用同一个仓库 你现在 /option-master/option-monitor/ 已经是 Git 仓库了。如果要同步到
    Windows: Linux 上先提交所有修改 cd /option-master/option-monitor
    git add -A && git commit -m “同步前提交” Windows 上用 U盘/网络共享/Syncthing 等方式 把整个 option-monitor 文件夹拷到 Windows 然后在 PyCharm 里直接打开这个文件夹即可 PyCharm 会自动识别 .git 目录,Git 标签里就能看到和 Linux
    上一样的提交历史。两边互相同步时需要注意路径差异(Linux 用
    /option-master/…,Windows 用 C:…),这个你之前已经用 hostname
    判断处理过了。

Comments

No comments yet. Why don’t you start the discussion?

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注