<b>阅读目录</b>
<a href="http://www.cnblogs.com/kaituorensheng/p/5954187.html#_label0">1. 忽略本地指定文件、目录</a>
<a href="http://www.cnblogs.com/kaituorensheng/p/5954187.html#_label1">2. 撤销对文件的修改</a>
<a href="http://www.cnblogs.com/kaituorensheng/p/5954187.html#_label2">3. 取消暂存(add)的文件</a>
<a href="http://www.cnblogs.com/kaituorensheng/p/5954187.html#_label3">4. 添加缓存(add)</a>
<a href="http://www.cnblogs.com/kaituorensheng/p/5954187.html#_label4">5. amend 补充提交</a>
<a href="http://www.cnblogs.com/kaituorensheng/p/5954187.html#_label5">6. 回退</a>
<a href="http://www.cnblogs.com/kaituorensheng/p/5954187.html#_label6">7. git 还原某个特定的文件到之前的版本</a>
<a href="http://www.cnblogs.com/kaituorensheng/p/5954187.html#_label7">8. git报错:Please move or remove them before you can switch branches.</a>
<a href="http://www.cnblogs.com/kaituorensheng/p/5954187.html#_label8">9. 还原指定的文件</a>
在git下载到本地的目录中修改.git/info/exclude文件
例如git status时忽略所有的.pyc文件
<a></a>
场景:当文件修改了,但没有add,还原最后一次提交的内容
注:使用之前需要确认确实要放弃之前的修改,否则会使内容彻底丢失。
场景:文件add了,但是突然想取消add操作,此时可用reset命令
场景:当commit 完了以后突然意识到还有文件没有提交,这时不需要再add+commit,可以amend到上次commit中
这样就把文件添加到上次commit了
先使用git log 查看 commit日志,找到需要回退的那次commit的 哈希值commit_id
以src/test.py为例
1
2
3
4
5
6
<code>error: Your local changes to the following files would be overwritten </code><code>by</code> <code>checkout:</code>
<code>.</code>
<code>.省略中间部分</code>
<code>Please move or remove them before you can </code><code>switch</code> <code>branches.</code>
出现这个错误时:可以通过以下的命令处理:
注:
2. d: 删除未被添加到git的路径中的文件
3. f: 强制执行
如果想拿远端Git服务器的最新版本(或指定版本)覆盖本地修改,可以用git pull,但这样会全面更新本地代码库
如果只想放弃本地工作所作修改(尚未add),可以用
<code>git checkout file/to/path</code>
如果想从远端库获取最新的更新,应先更新本地库,再跟新的本地
本文转自jihite博客园博客,原文链接:http://www.cnblogs.com/kaituorensheng/p/5954187.html,如需转载请自行联系原作者