Skip to content

Instantly share code, notes, and snippets.

@xdemocle
Last active April 5, 2017 17:01
Show Gist options
  • Save xdemocle/36511c92f47e1bc18ec5734921679f11 to your computer and use it in GitHub Desktop.
Save xdemocle/36511c92f47e1bc18ec5734921679f11 to your computer and use it in GitHub Desktop.
GIT Common troubleshooting

#GIT Common troubleshooting

##How to cancel a local git commit

Just use git reset without the --hard flag:

git reset HEAD~1

PS: On Unix based systems you can use HEAD^ which is equal to HEAD~1. On Windows HEAD^ will not work because ^ signals a line continuation. So your command prompt will just ask you More?.


##Keep local modifications in Git-tracked files

git update-index --skip-worktree FILENAME

Where “FILENAME” is the name of the file I want to keep local changes in.

To revert:

git update-index --no-skip-worktree <file>

##Pull just one file

git fetch

//git fetch will download all the recent changes, but it will not put it in your current checked out code (working area). followed by

git checkout origin/master -- path/to/file

//git checkout origin/master -- path/to/file will checkout the particular file from the the downloaded changes (origin/master).


##Revert a merged pull request on BitBucket

Note: Before you proceed, make sure your working copy is clean, with no uncommitted or unpushed changes.

So, you'll have to revert the merge in Git. First, find the SHA hash of the merge commit.

On the command line, this is:

git checkout <branch>
git pull
git log

Then, we revert the merge commit and push it:

git revert -m 1 <SHA-1>
git push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment