Remove a file from a Git repository without deleting it from the local filesystem

The git rm documentation states: When –cached is given, the staged content has to match either the tip of the branch or the file on disk, allowing the file to be removed from just the index. So, for a single file: git rm –cached file_to_remove.txt and for a single directory: git rm –cached -r directory_to_remove

Move existing, uncommitted work to a new branch in Git

Update 2020 / Git 2.23 Git 2.23 adds the new switch subcommand in an attempt to clear some of the confusion that comes from the overloaded usage of checkout (switching branches, restoring files, detaching HEAD, etc.) Starting with this version of Git, replace the checkout command with: git switch -c <new-branch> The behavior is identical … Read more

Undoing a git rebase

The easiest way would be to find the head commit of the branch as it was immediately before the rebase started in the reflog… git reflog and to reset the current branch to it (with the usual caveats about being absolutely sure before reseting with the –hard option). Suppose the old commit was HEAD@{2} in … Read more

tech