Skip to main content
  1. Learn center
  2. Software Development
  3. Guides
  4. Git tutorial
  5. 如何使用 Git
  6. 如何在 Command Line 中使用 Git
  7. 提交檔案
GuidesSoftware DevelopmentBacklog
Git

Project and code management together.

提交檔案

我們將新增一個新檔案,並將其註冊在我們剛建立的儲存庫中。

使用下列文本內容在該目錄中建立一個名為sample.txt的檔案。

Anyone can learn Git with this tutorial and Backlog

我們可以使用 git status 指令來確認tutorial目錄的狀態。

$ git status
On branch main
No commits yet
Untracked files:
  (use "git add <file>..." to include in what will be committed)
	sample.txt
nothing added to commit but untracked files present (use "git add" to track)

我們可以從回應中得知sample.txt目前未被追蹤。您必須先將sample.txt新增到索引中才能對其進行追蹤。

使用 git add 指令,然後是要新增到索引的檔案。如果要新增多個檔案,請用空格將它們隔開。然後驗證sample.txt是否已成功新增到索引中。

您可以指定.而不是單個檔案名稱,以將目前目錄中的所有檔案新增到索引中。

$ git add sample.txt
$ git status
On branch main
No commits yet
Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
	new file:   sample.txt

現在sample.txt已新增到索引中,我們可以繼續提交檔案。使用 git commit 指令,並再次檢查狀態。

$ git commit -m "first commit"
[main (root-commit) 13fc237] first commit
 1 file changed, 1 insertion(+)
 create mode 100644 sample.txt


$ git status
On branch main
nothing to commit, working tree clean

指令的回應告訴我們沒有更多的新變更要提交。

我們可以透過 git log 指令在儲存庫的歷史日誌中看到剛才新增的提交。

$ git log
  commit ac56e474afbbe1eab9ebce5b3ab48ac4c73ad60e
  Author: username
  Date:   Thu Jul 12 18:00:21 2022 +0900

      first commit

接下來,您已準備好與您的團隊共享儲存庫。

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life