Git Amend
Git กระทำ -- แก้ไข
commit --amend
commit
ใช้เพื่อ แก้ไขล่าสุด
มันรวมการเปลี่ยนแปลงในstaging environment
กับล่าสุดcommit
และสร้าง
commit
ใหม่
ใหม่นี้commit
แทนที่ล่าสุด
commit
ทั้งหมด
Git แก้ไขข้อความยืนยัน
สิ่งหนึ่งที่ง่ายที่สุดที่คุณสามารถทำได้--amend
คือเปลี่ยนcommit
ข้อความ
มาอัปเดตREADME.md
และ
commit
:
ตัวอย่าง
git commit -m "Adding plines to reddme"
[master 07c5bc5] Adding plines to reddme
1 file changed, 3 insertions(+), 1 deletion(-)
ตอนนี้ มาตรวจสอบlog
:
ตัวอย่าง
git log --oneline
07c5bc5 (HEAD -> master) Adding plines to reddme
9a9add8 (origin/master) Added .gitignore
81912ba Corrected spelling error
3fdaa5b Merge pull request #1 from w3schools-test/update-readme
836e5bf (origin/update-readme, update-readme) Updated readme for GitHub Branches
daf4f7c (origin/html-skeleton, html-skeleton) Updated index.html with basic meta
facaeae (gh-page/master) Merge branch 'master' of https://github.com/w3schools-test/hello-world
e7de78f Updated index.html. Resized image
5a04b6f Updated README.md with a line about focus
d29d69f Updated README.md with a line about GitHub
e0b6038 merged with hello-world-images after fixing conflicts
1f1584e added new image
dfa79db updated index.html with emergency fix
0312c55 Added image to Hello World
09f4acd Updated index.html with a new line
221ec6e First release of Hello World!
ไม่นะ! ข้อความcommit
เต็มไปด้วยการสะกดผิด น่าอาย. เอาเป็นว่า
amend
:
ตัวอย่าง
git commit --amend -m "Added lines to README.md"
[master eaa69ce] Added lines to README.md
Date: Thu Apr 22 12:18:52 2021 +0200
1 file changed, 3 insertions(+), 1 deletion(-))
และตรวจสอบอีกครั้งlog
:
ตัวอย่าง
git log --oneline
eaa69ce (HEAD -> master) Added lines to README.md
9a9add8 (origin/master) Added .gitignore
81912ba Corrected spelling error
3fdaa5b Merge pull request #1 from w3schools-test/update-readme
836e5bf (origin/update-readme, update-readme) Updated readme for GitHub Branches
daf4f7c (origin/html-skeleton, html-skeleton) Updated index.html with basic meta
facaeae (gh-page/master) Merge branch 'master' of https://github.com/w3schools-test/hello-world
e7de78f Updated index.html. Resized image
5a04b6f Updated README.md with a line about focus
d29d69f Updated README.md with a line about GitHub
e0b6038 merged with hello-world-images after fixing conflicts
1f1584e added new image
dfa79db updated index.html with emergency fix
0312c55 Added image to Hello World
09f4acd Updated index.html with a new line
221ec6e First release of Hello World!
เราเห็นก่อนหน้านี้commit
ถูกแทนที่ด้วยการแก้ไขของเรา!
คำเตือน:การยุ่งกับcommit
ประวัติของที่เก็บอาจเป็นอันตรายได้ เป็นเรื่องปกติที่จะทำการเปลี่ยนแปลงประเภทนี้กับที่เก็บในเครื่องของคุณเอง อย่างไรก็ตาม คุณควรหลีกเลี่ยงการเปลี่ยนแปลงที่เขียนประวัติไปยังที่
remote
เก็บใหม่ โดยเฉพาะอย่างยิ่งหากมีผู้อื่นกำลังทำงานด้วย
Git แก้ไขไฟล์
การ เพิ่มไฟล์ด้วย--amend
การทำงานในลักษณะเดียวกับด้านบน เพียงเพิ่มลงใน the
staging environment
ก่อนทำการคอมมิต