how to undo git clean -fd command 1

how to undo git clean -fd command

# Discarding local changes (permanently) to a file:
git checkout -- 

# Discard all local changes to all files permanently:
git reset --hard

Here is what the above code is Doing:
1. git fetch origin fetches any new work that has been pushed to that server since you cloned (or last fetched from) it.
2. git reset –hard origin/master resets the master branch to what you just fetched. The –hard option changes all the files in your working tree to match the files in origin/master.

If you have any local changes that you don’t want to keep, this is a good way to get rid of them.

If you don’t want to throw away all your local changes, there are other options.

If you just want to get rid of local changes to a specific file:

git checkout —

If you want to save your local changes to a new branch:

git branch my-saved-work
git reset –hard origin/master

If you want to save your local changes to a commit:

git commit -a
git reset –hard origin/master

If you want to save some changes and discard others:

git stash
git pull
git stash pop

If you want to save all your local changes and commits, but you want to discard all changes to files that have been added to the repository:

git stash –keep-index
git stash drop

If you want to save all your local changes and commits, but you want to discard all changes to files that have been added to the repository, and you want to discard all untracked files (like build products):

git stash –keep-index
git stash drop
git clean -fd

If you want to save all your local changes and commits, but you want to discard all changes to files that have been added to the repository, and you want to discard all untracked files (like build products), and you want to discard all ignored files:

git stash –keep-index
git stash drop
git clean -fdx

If you want to save all your local changes and commits, but you want to discard all changes to files that have been added to the repository, and you want to discard all untracked files (like build products), and you want to discard all ignored files, and you want to discard all stashes:

git stash –keep-index
git stash drop
git clean -fdx
git stash clear

If you want to save all your local changes and commits, but you want to discard all changes to files that have been added to the repository, and you want to discard all untracked files (like build products), and you want to discard all ignored files, and you want to discard all stashes, and you want to discard all local branches except master:

git stash –keep-index
git stash drop
git clean -fdx
git stash clear
git branch | grep -v “master” | xargs git branch -D

If you want to save all your local changes and commits, but you want to discard all changes to files that have been added to the repository, and you want to discard all untracked files (like build products), and you want to discard all ignored files, and you want to discard all stashes, and you want to discard all local branches except master, and you want to discard all tags:

git stash –keep-index
git stash drop
git clean -fdx
git stash clear
git branch | grep -v “master” | xargs git branch -D
git tag -l | xargs git tag -d

If you want to save all your local changes and commits, but you want to discard all changes to files that have been added to the repository, and you want to discard all untracked files (like build products), and you want to discard all ignored files, and you want

Similar Posts