git checkout -- filename
You can do it without the --
(as suggested by nimrodm), but if the filename looks like a branch or tag (or other revision identifier), it may get confused, so using --
is best.
You can also check out a particular version of a file:
git checkout v1.2.3 -- filename # tag v1.2.3
git checkout stable -- filename # stable branch
git checkout origin/master -- filename # upstream master
git checkout HEAD -- filename # the version from the most recent commit
git checkout HEAD^ -- filename # the version before the most recent commit
- Create branch
git branch BRANCHNAME git push -u origin BRANCHNAME
- Get it on another machine
git fetch origin git checkout --track origin/BRANCHNAME
- Delete
git push origin --delete BRANCHNAME
- Create Branch while preserving current changes
git checkout -b BRANCHNAME
cd /path/to/my/repo
git remote add origin_new https://new_repo_url/repo.git
git push -u origin_new --all # to push up the repo for the first time
git remote rm origin vim .git/config # edit the.git/config file to change the origin_new to origin.
git push origin_new master # Then push the content to the new location
git checkout -b BRANCH_NAME creates a new branch and goes to the new branch while git branch BRANCH_NAME creates a new branch but leaves you on the same branch. git checkout -b creates a branch and checks it out. It is the short for:
git branch name
git checkout name
http://www.gitguys.com/topics/temporarily-stashing-your-work/
git stash
git stash pop
If you want to revert changes made to your working copy, do this:
git checkout .
If you want to revert changes made to the index (i.e., that you have added), do this:
git reset
If you want to revert a change that you have committed, do this:
git revert ...
git clean -f But beware... there's no going back. Use -n or --dry-run to preview the damage you'll do.
If you want to also remove directories, run git clean -f -d
If you just want to remove ignored files, run git clean -f -X
If you want to remove ignored as well as non-ignored files, run git clean -f -x
Note the case difference on the X for the two latter commands.
If clean.requireForce is set to "true" (the default) in your configuration, then unless you specify -f nothing will actually happen, with a recent enough version of git.
Note that as of git-1.6.0, the dashed style of writing git commands (ie, git-clean instead of git clean) is obsoleted.
DANGER AHEAD: (please read the comments. Executing the command proposed in my answer might delete more than you want)
to completely remove all files including directories I had to run
git clean -f -d