يعمل في الطرفية: bash diff-restore.sh
#!/usr/bin/env bash
# التمرين 15.2: غيّر ملفاً، وانظر إلى التغيير بـ git diff، ثم تخلّص منه بـ git restore.
set -e
export GIT_AUTHOR_NAME="سارة خان" GIT_AUTHOR_EMAIL="sara@example.com"
export GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME" GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
export GIT_CONFIG_GLOBAL=/dev/null # تجاهل إعدادات Git الخاصة بك أثناء تشغيل السكربت
run() { local s="\$"; for a in "$@"; do if [[ $a == *" "* ]]; then s+=" \"$a\""; else s+=" $a"; fi; done; echo "$s"; "$@"; }
cd "$(mktemp -d)"
git init -q -b main
printf '<h1>Sara Khan</h1>\n<p>Beginner web developer</p>\n' > index.html
git add . && git commit -q -m "Add profile page"
echo "# تغيير سنندم عليه:"
printf '<h1>Sara Khan</h1>\n<p>Oops, I deleted my tagline</p>\n' > index.html
run git diff --no-color
run git restore index.html
run git status --short
run cat index.html
echo "# نظيف من جديد: الملف عاد إلى آخر إيداع."
الناتج المسجَّل$ bash diff-restore.sh
# تغيير سنندم عليه:
$ git diff --no-color
diff --git a/index.html b/index.html
index 96fec82..cba4b83 100644
--- a/index.html
+++ b/index.html
@@ -1,2 +1,2 @@
<h1>Sara Khan</h1>
-<p>Beginner web developer</p>
+<p>Oops, I deleted my tagline</p>
$ git restore index.html
$ git status --short
$ cat index.html
<h1>Sara Khan</h1>
<p>Beginner web developer</p>
# نظيف من جديد: الملف عاد إلى آخر إيداع.