Why are there two ways to unstage a file in Git?

git rm –cached <filePath> does not unstage a file, it actually stages the removal of the file(s) from the repo (assuming it was already committed before) but leaves the file in your working tree (leaving you with an untracked file). git reset — <filePath> will unstage any staged changes for the given file(s). That said, … Read more

Need to reset git branch to origin version

If you haven’t pushed to origin yet, you can reset your branch to the upstream branch with: (Make sure that you reference your latest commit in a separate branch, like you mention in your question) Note that just after the reset, mybranch@{1} refers to the old commit, before reset. But if you had already pushed, … Read more

Practical uses of git reset –soft?

git reset is all about moving HEAD, and generally the branch ref.Question: what about the working tree and index?When employed with –soft, moves HEAD, most often updating the branch ref, and only the HEAD.This differ from commit –amend as: it doesn’t create a new commit. it can actually move HEAD to any commit (as commit … Read more

Delete commits from a branch in Git

Careful: git reset –hard WILL DELETE YOUR WORKING DIRECTORY CHANGES. Be sure to stash any local changes you want to keep before running this command. Assuming you are sitting on that commit, then this command will wack it… The HEAD~1 means the commit before head. Or, you could look at the output of git log, … Read more

Handling file renames in Git

For git mv the manual page says The index is updated after successful completion, […] So, at first, you have to update the index on your own (by using git add mobile.css). However git status will still show two different files: You can get a different output by running git commit –dry-run -a, which results … Read more

Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools)

The problem is that Xcode Command-line Tools needs to be updated. Solution #1 Go back to your terminal and enter: You’ll then receive the following output: You will then be prompted in a window to update Xcode Command Line tools. (which may take a while) Open a new terminal window and your development tools should … Read more

How to uncommit my last commit in Git [duplicate]

If you aren’t totally sure what you mean by “uncommit” and don’t know if you want to use git reset, please see “Revert to a previous Git commit”. If you’re trying to understand git reset better, please see “Can you explain what “git reset” does in plain English?”. If you know you want to use git reset, it still … Read more