هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.
$ مستخدم عادي# بصلاحية root (أو مع sudo)
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| Command | Effect |
|---|---|
git restore FILE | Back to the last staged/committed version (changes lost) |
git restore --staged FILE | Unstage, keep the changes |
git restore --source=COMMIT FILE | Get the file from any commit |
git clean -n / -fd | Show / delete untracked files and folders |
انتبه
git restore and git clean -f delete work that was never committed — there is no undo for that.
Fix the last commit
Forgot a file or wrote a bad message? --amend replaces the last commit — only if it is not pushed yet.
Move a branch back with reset
git reset moves the branch pointer to an older commit. The mode decides what happens to your files.
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.
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.