الفلاتر
طريقة البحث
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • "كلمتان" تجد العبارة بالضبط.
  • --name أو -x تجد خيارًا.
  • #كلمة تبحث داخل الأوامر فقط.
  • @grep تجد الدروس والمعامل التي تستخدم grep.
  • الفلاتر: cat:network · in:labs · level:rhcsa · ch:8 · root:yes. ضع ! قبل كلمة لاستبعادها. OR بين الكلمات تعني إحداها.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث

الفصل 2الاسم في الدورة: Undoing things

Undo changes safely

Mistakes happen: a wrong file staged, a bad commit, a broken change already pushed. Git can undo almost everything — if you choose the right command. The rule: rewrite only what you have not shared; revert what others already have.

  • 5 الدروس
  • 1 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

2.1

Undo changes in files

git restore throws away changes in the working tree, or takes a file out of the staging area.

git restore main.tf
git restore --staged main.tf
git restore --source=HEAD~2 variables.tf
git clean -n
git clean -fd
CommandEffect
git restore FILEBack to the last staged/committed version (changes lost)
git restore --staged FILEUnstage, keep the changes
git restore --source=COMMIT FILEGet the file from any commit
git clean -n / -fdShow / delete untracked files and folders

انتبه

git restore and git clean -f delete work that was never committed — there is no undo for that.

الأوامر في هذا الدرس

2.2

Fix the last commit

Forgot a file or wrote a bad message? --amend replaces the last commit — only if it is not pushed yet.

git add forgotten.tf
git commit --amend --no-edit
git commit --amend -m "Better message"

الأوامر في هذا الدرس

2.3

Move a branch back with reset

git reset moves the branch pointer to an older commit. The mode decides what happens to your files.

git reset --soft HEAD~1
git reset HEAD~1
git reset --hard HEAD~1
git reset --hard origin/main
ModeCommits after the targetStaging areaWorking tree
--softRemovedKeeps the changes (staged)Kept
--mixed (default)RemovedClearedKept (changes unstaged)
--hardRemovedClearedReset — changes lost

الأوامر في هذا الدرس

2.4

Undo a pushed commit with revert

git revert makes a new commit that does the opposite of an old one. History stays intact — safe on shared branches.

git log --oneline -5
git revert 3f2a9c1
git revert --no-edit HEAD
git revert -m 1 MERGE_COMMIT
git push

تذكّر

Pushed = shared. On shared branches use revert, never reset + force push.

الأوامر في هذا الدرس

2.5

Find "lost" commits with reflog

The reflog records where HEAD was. After a bad reset or rebase, the old commits are still there for some weeks.

git reflog
3f2a9c1 HEAD@{0}: reset: moving to HEAD~3
8b7c6d5 HEAD@{1}: commit: Add monitoring module
git reset --hard HEAD@{1}
git branch rescue 8b7c6d5

في العمل

Before a risky operation, make a backup branch: git branch backup-before-rebase. It costs nothing.

الأوامر في هذا الدرس

كل الأوامر في هذا الفصل