Best thing is to correct mistakes in a new commit and push it.
~
But if you want to wipe off history from the current branch and go back to an older commit even if it is not the last one.
Step 1) rebase has an interactive version that opens editor to choose all commits we want to pick or drop after the target commit.
git rebase -i target-commit
if one wishes to drop all the commits, replace pick with drop.
if one wishes to drop one of them, just delete the line using dd (vi editor)
Step 2) force push to the current branch.
git push
OR
If you would like to keep the history and create a new commit
git revert target-commit
2) How to undo a git add - remove files staged for a git commit?
git reset filename.txt
Will remove a file named filename.txt from the current index, the "about to be committed" area, without changing anything else.
3) How to undo git add . ?
use git reset (no dot).
4) How do I remove a folder from my git repository without deleting it from my local machine (i.e., development environment)?
Step 1. Add the folder path to the repo's root .gitignore file.
path_to_your_folder/
Step 2. Remove the folder from your local git tracking, but keep it on your disk.
git rm -r --cached path_to_your_folder/
Step 3. Push your changes to your git repo.
git push
The folder will be considered "deleted" from Git's point of view (i.e. they are in past history, but not in the latest commit, and people pulling from this repo will get the files removed from their trees), but stay on your working directory because you've used --cached.
5) How to delete a branch?
Local branch
git branch -d local-branch
Remote branch
git push origin remote-branch
If the above displays the following, someone else has already deleted the branch.
To synchronize your branch list with remoteerror: unable to push to unqualified destination: the_remote_branch The destination refspec neither matches an existing ref on the remote nor begins with refs/, and we are unable to guess a prefix based on the source ref. error: failed to push some refs to 'git@repository_name'git fetch -p
No comments:
Post a Comment