Gitกวดวิชา


Gitและ {{title}}


Git Contribute


Git Advanced


Git Undo




Git Staging Environment


Git Staging Environment

หนึ่งในหน้าที่หลักของ Git คือแนวคิดของ Staging Environment และ Commit

ขณะที่คุณทำงาน คุณอาจกำลังเพิ่ม แก้ไข และลบไฟล์ แต่เมื่อใดก็ตามที่คุณบรรลุเป้าหมายหรืองานบางส่วนเสร็จสิ้น คุณควรเพิ่มไฟล์ไปยัง Staging Environment

ไฟล์แบบส เตจคือไฟล์ที่พร้อมจะ คอม มิตกับที่เก็บที่คุณกำลังทำงานอยู่ คุณจะได้เรียนรู้เพิ่มเติม commitในไม่ช้า

สำหรับตอนนี้ เราเสร็จสิ้นการทำงานกับindex.html. ดังนั้นเราจึงสามารถเพิ่มไปยัง Staging Environment:

ตัวอย่าง

git add index.html

ไฟล์ควรเป็นStaged มาเช็คสถานะกัน::

ตัวอย่าง

git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
    new file: index.html

ตอนนี้ไฟล์ถูกเพิ่มไปยัง Staging Environment แล้ว


Git เพิ่มมากกว่าหนึ่งไฟล์

คุณยังสามารถจัดฉากได้มากกว่าหนึ่งไฟล์ในแต่ละครั้ง มาเพิ่มอีก 2 ไฟล์ในโฟลเดอร์การทำงานของเรา ใช้โปรแกรมแก้ไขข้อความอีกครั้ง

README.mdไฟล์ที่อธิบายที่เก็บ (แนะนำสำหรับที่เก็บทั้งหมด) :

ตัวอย่าง

# hello-world
Hello World repository for Git tutorial
This is an example repository for the Git tutoial on https://www.w3schools.com

This repository is built step by step in the tutorial.

สไตล์ชีตภายนอกพื้นฐาน ( bluestyle.css):

ตัวอย่าง

body {
background-color: lightblue;
}

h1 {
color: navy;
margin-left: 20px;
}

และอัปเดตindex.htmlเพื่อรวมสไตล์ชีต:

ตัวอย่าง

<!DOCTYPE html>
<html>
<head>
<title>Hello World!</title>
<link rel="stylesheet" href="bluestyle.css">
</head>
<body>

<h1>Hello world!</h1>
<p>This is the first file in my new Git Repo.</p>

</body>
</html>

เพิ่มไฟล์ทั้งหมดในไดเร็กทอรีปัจจุบันไปยัง Staging Environment:

ตัวอย่าง

git add --all

การใช้--allแทนชื่อไฟล์แต่ละไฟล์จะstageเปลี่ยนแปลงไฟล์ทั้งหมด (ใหม่ แก้ไข และลบ)

ตัวอย่าง

git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   README.md
        new file:   bluestyle.css
        new file:   index.html

ตอนนี้ทั้ง 3 ไฟล์ถูกเพิ่มไปยัง Staging Environment และเราพร้อมที่จะทำcommitไฟล์ .

หมายเหตุ:คำสั่งชวเลขสำหรับ git add --allisgit add -A


ทดสอบตัวเองด้วยแบบฝึกหัด

ออกกำลังกาย:

เพิ่ม index.html ในสภาพแวดล้อมที่ระบุ:

git  index.html