مشخصات مقاله
-
377
-
0.0
-
2394
-
0
-
0
دستور Amend در Git
Git Amend
commit - - amend
دستور commit - - amend معمولا برای ویرایش آخرین commit استفاده میشود.
این دستور تغییرات موجود در staging environment را با آخرین commit ترکیب کرده و یک commit جدید ایجاد میکند.
این commit جدید با آخرین commit جایگزین میشود.
Message برای Amend Commit
یکی از ساده ترین کاربرد های دستور - - amend ، تغییر message یک commit است.
مثلا در این بخش، commit و README.md را به روز رسانی میکنیم:
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 اصلا توصیه نمیشود. البته اگر بر repository خودتان کار میکند تغییرات کوچک مشکلی ایجاد نخواهد کرد، اما از ایجاد تغییراتی که باعث حذف و یا باز نویسی تاریخچه remote repository میشود اجتناب کنید. مخصوصا اگر این repo مورد استفاده ی چند نفر باشد.
فایل های Amend
اضافه کردن فایل با استفاده از دستور - - amend نیز کارکردی دقیقا مشابه بالا دارد. کافی است پیش از commit کردن، آنها را به staging environment اضافه کنید.