Git amend
Git amend
Git amend nima?
Git amend — eng so‘nggi commit’ni o‘zgartirish imkonini beruvchi buyruq.
Undan imlo xatolarini tuzatish, fayllar qo‘shish yoki olib tashlash yoxud commit xabarini o‘zgartirish uchun foydalanishingiz mumkin.
Git amend’dan qachon foydalanish kerak
Oxirgi commit’ingizga kichik o‘zgartirishlar kiritishingiz kerak bo‘lganda Git amend’dan foydalaning.
U xatolarni tuzatish, unutilgan fayllarni qo‘shish yoki commit xabarini yangilash uchun juda mos.
Oxirgi commit xabarini tuzatish
Oxirgi commit xabarini o‘zgartirish uchun quyidagi qadamlarni bajaring:
- Terminalingizni oching va repozitoriyingizga o‘ting.
- Commit xabarini o‘zgartirish uchun
git commit --amend -m "New message"deb yozing. - O‘zgarishlarni saqlash uchun Enter tugmasini bosing.
Misol
git commit --amend -m "Corrected commit message"
Oxirgi commit’ga fayllar qo‘shish
Oxirgi commit’ga fayllar qo‘shish uchun quyidagi qadamlarni bajaring:
- Terminalingizni oching va repozitoriyingizga o‘ting.
- Faylni staging hududiga qo‘shish uchun
git add <file>deb yozing. - Faylni oxirgi commit’ga qo‘shish uchun
git commit --amenddeb yozing. - O‘zgarishlarni saqlash uchun Enter tugmasini bosing.
Misol
git add forgotten.txt
git commit --amend
Oxirgi commit’dan fayllarni olib tashlash
Oxirgi commit’dan fayllarni olib tashlash uchun quyidagi qadamlarni bajaring:
- Terminalingizni oching va repozitoriyingizga o‘ting.
- Faylni staging hududidan olib tashlash uchun
git reset HEAD^ -- <file>deb yozing. - Faylni oxirgi commit’dan olib tashlash uchun
git commit --amenddeb yozing. - O‘zgarishlarni saqlash uchun Enter tugmasini bosing.
Misol
git reset HEAD^ -- unwanted.txt
git commit --amend
1 file changed, 3 insertions(+), 1 deletion(-)
Endi log’ni tekshiraylik:
Misol
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!
Voy! commit xabari imlo xatolariga to‘la.
Noqulay holat. Keling, uni amend yordamida tuzataylik:
Misol
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(-))
Va log’ni qayta tekshiring:
Misol
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!
Oldingi commit biz tuzatgan commit bilan almashtirilganini ko‘ramiz!
Ogohlantirish: Repozitoriyning commit tarixiga aralashish xavfli bo‘lishi mumkin.
Odatda bunday o‘zgarishlarni o‘zingizning lokal repozitoriyingizda qilish mumkin.
Biroq remote repozitoriylarda, ayniqsa ular bilan boshqalar ham ishlayotgan bo‘lsa, tarixni qayta yozadigan o‘zgarishlardan saqlanishingiz kerak.
Git amend bilan fayllar qo‘shish
--amend yordamida fayllar qo‘shish yuqoridagi kabi ishlaydi.
Commit qilishdan oldin ularni shunchaki staging environment’ga qo‘shing.
W3Schools Pathfinder
Yutuqlaringizni kuzating – bu bepul!

GitHub
Bitbucket
GitLab