If you have found this page you probably came here since you wanted to clear your working directory from all the changes that you have made.
The simple answer is:
# Clear working directory tree from all changes $ git checkout -f HEAD
This is, however, not the best way to do it. A better way is:
# Clears the working directory tree, and stashes all the changes. $ git stash
git stash allows you to get your changes back any time you need them in case you change your mind. It is also possible to inspect and manipulate the stashes.
# List all the stashes $ git stash list stash@{0}: WIP on admin_ui: 0c1a80a Removed annotation from JdbcAdminService, it is now explicity initialized in the applicationContext. stash@{1}: WIP on admin_ui: 14e12e6 Added foreign keys for UserRole stash@{2}: WIP on master: d188ecd Merge branch 'master' of semc-git:customercare stash@{3}: WIP on master: 3763795 More work on user_details. ... # Apply the latest stash, and remove it from the stack $ git stash pop # Apply a named patch, but leave it on the stack $ git stash apply stash@{2} # Drop a stash $ git stash drop stash@{3} # Clear the entire stash stack (almost never needed) $ git stash clear # A better way to purge the stash $ git reflog expire --expire=30.days refs/stash
What about git reset then, it sounds like it should do about the same as git co -f HEAD. It doesn't. git reset is used for setting the current reference pointer, HEAD.
# Reset the latest commit, and leave the changes in the index. $ git reset --soft HEAD^ # Reset the latest commit, and leave the changes in the working directory $ git reset HEAD^ # Reset some commits $ git reset --head HEAD~2 # Undo add, move the changes from the index to the working directory $ git reset # Reset the latest successful pull or merge $ git reset --hard ORIG_HEAD # Reset the latest failed pull or merge $ git reset --hard # Reset the latest pull or merge, into a dirty working tree $ git reset --merge ORIG_HEAD
You can do more things with reset, but the above covers the typical cases. And now to the last thing, git revert. What does it do? git revert creates a new commit that is the opposite of the commit it names.
# Show the commits $ git log --oneline 4717a5c new line 7e38e95 added tapir file # Revert the commit named, 4717a5c, and commit it. $ git revert 4717a5c # Revert the HEAD commit, but don't commit it $ git revert -n HEAD
Git is incredibly flexible and lets you control everything if you want to.
相关推荐
Git-2.33.1-64-bit和Git-2.28.0-64-bit.exe
Git-2.28.0-64-bit.exe Git-2.28.0-64-bit.exe Git-2.28.0-64-bit.exe
git-lfs-windows-v3.2.0.exe
git-2.41.0-64-bit window版本下载
Git-2.15.1.2-64-bit和Git-2.15.1.2-32-bit以及常用命令行git-cheatsheet.PDF
Git是目前非常流行的分布式版本控制系统,由Linus Torvalds为Linux内核开发而创建,该资源包含 Git-2.42.0-64-bit-windows安装版,仅供学习,下载后请及时删除 Git是目前非常流行的分布式版本控制系统,由Linus ...
最新版的git安装包(Git-2.13.2-64-bit)
Git-2.23.0-64-bit.zip
Git-2.12.0-64-bit 64位下载
windows xp git安装包 Git-2.10.0-32-bit,支持Windows XP 32位系统
git 管理工具 Git-2.21.0-64-bit安装包.rar
Git-2.24.0.2-64-bit.exe 国外站点下载异常慢,上传一个,节约你宝贵的时间。 介绍 这些发行说明描述了特定于Windows的Git版本的问题。可以在Git项目中找到涵盖核心git命令历史的发行说明。 有关Git的更多详细...
最新版windows Git-2.33.1-64-bit.exe最新版windows Git-2.33.1-64-bit.exe
官方下载地址:https://github.com/git-for-windows/git/releases/download/v2.17.1.windows.2/Git-2.17.1.2-64-bit.exe 如果能官网下载,就没必要在这下载了,这里只是提供由于特殊原因不能在官网下载的。
Git-2.40.0-64-bit.exe Git是一个免费的开源分布式版本控制系统,可以快速高效地处理从小到大的所有项目。Git易于学习,占用空间小,性能却非常快。它超越了像Subversion、CVS、Perforce和ClearCase这样的配置管理...
Git-2.42.0.2-64-bit.ex
git工具 最新版本 Git-2.15.1.2-64-bit windows 64位系统
git-lfs安装包
Git-2.10.0-32-bit_++++_TortoiseGit-1.8.16.0-32bit.rar 自己使用
Git-2.41.0.3-64-bit.exe