Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Introduction to Git for Data Science
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Alex
January 07, 2019
Technology
300
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Introduction to Git for Data Science
Alex
January 07, 2019
More Decks by Alex
See All by Alex
How to integrate GitLab CICD into B2B service.pdf
alexsu
0
310
Jenkins Quick Guide
alexsu
0
140
Vim 基本操作
alexsu
1
140
Top IDEs & Code Editors for Data Science
alexsu
0
46
Shell scripting 基本教學
alexsu
0
50
Linux_Command-line_指令與基本操作.pdf
alexsu
0
120
Other Decks in Technology
See All in Technology
[RSJ26] NarrativeFlow: Flow-Based Vision-Language-Action Model Using Robot Velocity Fields
keio_smilab
PRO
0
160
Webとヘルスデータ
yukukotani
0
180
Guerilla InnerSource in enterprises, during the AI hype
onenashev
PRO
0
150
[DroidKaigi 2026] Making UI specifications visible: Android UI development in the AI agent era supported by Compose Screenshot Testing and galleries
syarihu
0
570
AI 駆動 Terraform 開発/SRE_BizReach_MIXI_2
visional_engineering_and_design
0
370
[RSJ26] AnoleVLA: Lightweight Vision-Language-Action Model with Deep State Space Models for Mobile Manipulation
keio_smilab
PRO
0
120
Bet AI Day 2026丨How We Bet AI: AIとともに働く場をつくる
layerx
PRO
2
2.2k
Amazon S3 Tablesに全部任せてみた結果——コンパクション/スナップショット管理は本当に手放せるか
shigeruoda
0
380
Azure Cost Management の FOCUS コストデータを迷わず読むための“3つの軸”
tetsuyaooooo
0
140
grill-me(grilling):AI駆動開発を超助けてくれるSkill / grill me
mathbullet
0
110
多層防御と最⼩権限で実現する、安全なAIエージェント設計パターン
lycorptech_jp
PRO
0
190
Redmine 7.0で私が開発した新機能の狙いと背景
vividtone
1
110
Featured
See All Featured
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
230
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.6k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
770
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Raft: Consensus for Rubyists
vanstee
141
7.7k
The agentic SEO stack - context over prompts
schlessera
0
890
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
560
New Earth Scene 8
popppiees
3
2.5k
Navigating Weather and Climate Data
rabernat
0
510
The Language of Interfaces
destraynor
162
27k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.1k
Transcript
Introduction to Git for Data Science 蘇民弦 (Alex)
如何備份多次修改過的檔案
方法一:更改檔案名稱
方法二:雲端儲存服務 Dropbox Google Drive
更改檔案名稱 雲端儲存 • 簡單方便 • 耗費硬碟空間 • 僅適用檔案不多的情況 • 比較適合同步、分享檔案
• 需要有額外的雲端空間 • 無法追蹤特定的修改記錄
What is version control • 記錄檔案在某一段時間的變更,使得以後 能取回特定版本的系統。 • 遊戲中的存檔點,檔案目錄的時光機器。 •
集中式 (Centralized) V.S. 分散式 (Distributed)
What is Git • 屬於分散式版本控制系統。 • 具有檔案暫存區,新增修改時方便自己查看 檔案變化。 • 免費、開源、輕量、安全。
Why Git for Data Science • 將資料分析方法的程式碼放在公開的 GitHub 遠端儲存庫。 •
製作統計分析或視覺化工具,分享給其他人 使用。 • 替文本和統計分析模型做版本控制。 • 允許多人協作與追蹤。
Git Cloud Storage • GitHub - 全球最大的工程師交友平台。 • BitBucket -
由 Atlassian 公司開發。 • GitLab - 開源、多為私人公司使用。 • Gitea - 輕量,基於 GO 語言。
Git GUI Tools • SourceTree - 操作簡單功能強大,由 Atlassian 公司 開發。
• GitKraken - 重視 UI,軟體稍微笨重一點,由 Axosoft 公司開發。 • GitHub Desktop - 由 GitHub 開發,適合新手使用。 • Tower - 多為 MacOS 用戶使用。
A Basic Workflow Master Dev Test Time • Create a
repository • Observe your repository • Working with Branch • Saving Changes • Syncing • Making a Pull Request (PR) branching merging merging commit commit
How to install Git on Windows, Linux and MacOS Ubuntu
/ Debian Direct Download from Git Website Homebrew $ brew install git $ apt-get install git $ pacman -Sy git $ yum install git Arch Linux Fedora / CentOS
Basic Git Command $ 指令名稱 + 參數 + [目標對象] #
備註
Git 基本設定
Tell Git Who You Are $ git config --global user.name
alexsu $ git config --global user.email
[email protected]
Other Basic Settings $ git config --global core.editor emacs #
更改編輯器 $ git config --list # 列出所有設定 $ vim ~/.gitconfig # 編輯設定
將檔案加入 Git 控管
Create A Repository $ git init MyProject # 初始化還沒加入 git
控管的專案
兩個步驟提交版本 Working Directory Staging Area Repository git add git commit
V1 V2
Saving Changes $ git add [file] # 將單一個檔案加進暫存區 $ git
add . # 將全部檔案加進暫存區 $ git commit # 提交檔案 (跳出文字編輯視窗) $ git commit -m [commit message] # 提交檔案
檢查檔案修改狀態
Observe Repository $ git status # 顯示檔案當前的狀態 $ git diff
[hash_id1] [hash_id2] # 顯示兩個 commit 改了什麼 $ git log --oneline # 顯示 commit 歷史紀錄 $ git reflog # 顯示所有的操作紀錄 $ git blame [file] # 顯示是誰修改了紀錄 (友情破壞者)
Create / Merge Branch
Working with Branches $ git branch test # 建立名為 test
的新分支 $ git checkout test # 建立並且切換至名為 test 的新分支 $ git merge test # 合併名為 test 的分支 $ git rebase test # 合併名為 test 的分支 (移花接木合併法)
Working with Remote Repository
SSH Key 免密碼登入 $ ssh-keygen # 產生 SSH Key $
cd ~/.ssh # SSH Key 位在根目錄的資料夾內 $ ls # 檢查目錄底下的檔案 # 會出現三個檔案:id_dsa id_dsa.pub known_hosts
將 Public Key 貼到 GitHub
Syncing with Remote Repository $ git clone [repo url] #
複製已經存在的 repository $ git remote add [alias] [remote repo url] # 增加遠端倉庫 $ git fetch # 取得遠端倉庫的內容,但不合併 $ git pull # 取得並且合併遠端倉庫的 內容 $ git push [alias] [branch] # 推送本地分支至遠端倉庫
GitHub 多人協作 Pull Request
https://github.com/doggy8088/Learn-Git-in-30-days Fork 一份專案到自 己的目錄底下
自己會變成這 個專案擁有者
Clone 到本機端 修改
建立 PR 新增修改 的檔案 專案資訊
像寫信那樣撰寫訊息 寫完提交
Dealing With Git Merge Conflicts
Merge Conflicts Discussion & Commit Again Solve Merge Conficts $
git merge [branch] $ cat merge.txt # 發生 conflict 的文 件 <<<<<<< HEAD Content A ======= Content B >>>>>>> branch 討論發生衝突原因,並決定採取誰的 更動,修改過後重新 commit 一次。
修改過去的 commit
新增一個 commit 回到過去 $ git revert HEAD # 新增一個 commit
回復到上一個 commit 的內容 $ git revert HEAD --no-edit # 同上,但不修改 commit 訊息 $ git revert [hash_id] # 新增一個 commit 回復到 [hash_id] 的內容。 $ git revert HEAD~3 # 新增一個 commit 回復到前三次的 commit。 # revert 指令不會修改 commit 的歷史,所以有可能會有衝突發生
回到過去那次的 commit $ git reset --hard HEAD^ # 使用 hard
模式取消上一次合併 $ git reset [hash_id] # 取消 [hash_id] 那次的提交 # git reset 共有三種砍掉重練的模式: --mixed (default, 只丟掉暫存區檔案) --soft (檔案皆保存) --hard (把所有檔案丟掉)
修改時間線 $ git rebase -i [hash_id] # 開啟 rebase 交互視窗
舊 新 • pick: 已存在的修改 • reword: 更改 commit 訊息
• squash: 合併新舊分支 • drop: 刪除某次的 commit
其他常用的修改指令 $ git commit --amend # 修改上一個提交訊息 $ git reset
HEAD [file] # 將檔案移出暫存區 $ git checkout -- [file] # 取消檔案修改 $ git checkout [hash_id] [file] # 將某個檔案回到過去某次的修改。
其他 Git 小技巧
增加標籤
增加標籤 $ git tag [tag_name] [hash_id] # 新增 lightweight tag
(輕量標籤) $ git tag [tag_name] [hash_id] -a -m [message] # 新增 annotated tag (有附註的標籤) $ git show # 觀察標籤
Import 別人的專案到自己的專案
$ git submodule [git url] # 將其他專案 import 到自己的專案目錄底下 增加子模組
暫時儲存手邊的工作進度
$ git stash # 將手邊目前的進度加入 stash 裡面 $ git stash
list # 查看目前的 stash $ git stash apply [stash ID] # 回到 stash 前的狀態 Git 儲藏
Summary 基本指令 操作分支 修改過去 $ git add $ git init
$ git commit $ git remote $ git push $ git clone $ git pull $ git branch $ git checkout $ git merge $ git rebase $ git revert $ git reset $ git rebase 觀察狀態 $ git status $ git diff $ git blame $ git log $ git show $ git reflog 其他指令 $ git tag $ git submodule $ git stash
常見的團隊協作流程:GitHub flow
常見的團隊協作流程:Gitflow
References • Git Website • Atlassian Git Tutorial • Tower
Git Tutorial • 30 天精通 Git 版本控管 • 為你自己學 git
Exercise • Git 基本設定 • 將自己的一份專案加入 Git 控管 • 練習
Branch / Merge / Rebase / Reset 等操作 • 安裝一個 GUI 軟體,觀察 Git Tree 的狀態 • 練習解決 Merge Conflict • 練習提交 Pull Request