Git提交与恢复

提交修改

git add --all # 提交所有修改文件

git add file file # 提交部分修改文件

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage) modified: src/Makefile.am Untracked files:
(use "git add <file>..." to include in what will be committed) spice-gtk.IAB
spice-gtk.IAD
spice-gtk.IMB
spice-gtk.IMD
spice-gtk.PFI
spice-gtk.PO
spice-gtk.PR
spice-gtk.PRI
spice-gtk.PS
spice-gtk.SearchResults
spice-gtk.WK3 fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
$ git add --all fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
$

回退提交的文件

git reset file # 将执行过git add的某个文件从缓存区恢复到工作文件

git reset -- . # 将执行过git add的所有文件从缓存区恢复到工作文件

git reset --soft id # 将版本回退到对应的commit但保留之后所有commit的修改

git reset --hard id # 将版本回退到对应的commit并放弃之后所有commit的修改

$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage) modified: src/Makefile.am Untracked files:
(use "git add <file>..." to include in what will be committed) spice-gtk.IAB
spice-gtk.IAD
spice-gtk.IMB
spice-gtk.IMD
spice-gtk.PFI
spice-gtk.PO
spice-gtk.PR
spice-gtk.PRI
spice-gtk.PS
spice-gtk.SearchResults
spice-gtk.WK3 fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
$ git reset src/Makefile.am
Unstaged changes after reset:
M src/Makefile.am fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory) modified: src/Makefile.am Untracked files:
(use "git add <file>..." to include in what will be committed) spice-gtk.IAB
spice-gtk.IAD
spice-gtk.IMB
spice-gtk.IMD
spice-gtk.PFI
spice-gtk.PO
spice-gtk.PR
spice-gtk.PRI
spice-gtk.PS
spice-gtk.SearchResults
spice-gtk.WK3 no changes added to commit (use "git add" and/or "git commit -a") fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
$ git add --all fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
$ git reset -- .
Unstaged changes after reset:
M src/Makefile.am fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory) modified: src/Makefile.am Untracked files:
(use "git add <file>..." to include in what will be committed) spice-gtk.IAB
spice-gtk.IAD
spice-gtk.IMB
spice-gtk.IMD
spice-gtk.PFI
spice-gtk.PO
spice-gtk.PR
spice-gtk.PRI
spice-gtk.PS
spice-gtk.SearchResults
spice-gtk.WK3 no changes added to commit (use "git add" and/or "git commit -a") fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory) modified: src/Makefile.am Untracked files:
(use "git add <file>..." to include in what will be committed) spice-gtk.IAB
spice-gtk.IAD
spice-gtk.IMB
spice-gtk.IMD
spice-gtk.PFI
spice-gtk.PO
spice-gtk.PR
spice-gtk.PRI
spice-gtk.PS
spice-gtk.SearchResults
spice-gtk.WK3 no changes added to commit (use "git add" and/or "git commit -a") fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
$ git add --all fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
$ git commit -m "top"
[master ff418e2] top
12 files changed, 2 insertions(+)
create mode 100644 spice-gtk.IAB
create mode 100644 spice-gtk.IAD
create mode 100644 spice-gtk.IMB
create mode 100644 spice-gtk.IMD
create mode 100644 spice-gtk.PFI
create mode 100644 spice-gtk.PO
create mode 100644 spice-gtk.PR
create mode 100644 spice-gtk.PRI
create mode 100644 spice-gtk.PS
create mode 100644 spice-gtk.SearchResults
create mode 100644 spice-gtk.WK3 fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
nothing to commit, working directory clean fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
$ git log
commit ff418e286d14eb75c3cc2227b65e79ccdc8b2b19
Author: silvermagic <fwdssg@gmail.com>
Date: Thu Jun 23 14:41:16 2016 +0800 top commit 2293b293e83a95a9b939a04a916adf8abed1a100
Author: Takao Fujiwara <tfujiwar@redhat.com>
Date: Fri Apr 15 18:09:37 2016 +0900 Send Hangul key in KR keyboard Korean keyboard assigns Hangul key on the position of Right Alt and
Left Alt and Hangul keys have the different scancodes but MapVirtualKey()
returned the same scancode and could not use Hangul key on Linux desktop. The fix is to send the right scancode of VK_HANGUL. commit 046de27c2eea2b3ee2ade80780f51b2ca140f92d
Author: Takao Fujiwara <tfujiwar@redhat.com>
Date: Fri Apr 15 18:08:37 2016 +0900 Send key release event for some keys in JP keyboard fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
$ git reset --soft 2293b293e83a95a9b939a04a916adf8abed1a100 fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
$ git reset -- .
Unstaged changes after reset:
M src/Makefile.am fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory) modified: src/Makefile.am Untracked files:
(use "git add <file>..." to include in what will be committed) spice-gtk.IAB
spice-gtk.IAD
spice-gtk.IMB
spice-gtk.IMD
spice-gtk.PFI
spice-gtk.PO
spice-gtk.PR
spice-gtk.PRI
spice-gtk.PS
spice-gtk.SearchResults
spice-gtk.WK3 no changes added to commit (use "git add" and/or "git commit -a") fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
$ git add src/Makefile.am fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
$ git commit -m "top"
[master 5edeb81] top
1 file changed, 1 insertion(+) fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
$ git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
Untracked files:
(use "git add <file>..." to include in what will be committed) spice-gtk.IAB
spice-gtk.IAD
spice-gtk.IMB
spice-gtk.IMD
spice-gtk.PFI
spice-gtk.PO
spice-gtk.PR
spice-gtk.PRI
spice-gtk.PS
spice-gtk.SearchResults
spice-gtk.WK3 nothing added to commit but untracked files present (use "git add" to track) fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
$ git reset --hard 2293b293e83a95a9b939a04a916adf8abed1a100
HEAD is now at 2293b29 Send Hangul key in KR keyboard fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
(use "git add <file>..." to include in what will be committed) spice-gtk.IAB
spice-gtk.IAD
spice-gtk.IMB
spice-gtk.IMD
spice-gtk.PFI
spice-gtk.PO
spice-gtk.PR
spice-gtk.PRI
spice-gtk.PS
spice-gtk.SearchResults
spice-gtk.WK3 nothing added to commit but untracked files present (use "git add" to track) fwdss@DESKTOP-N07EPED MINGW64 /d/Project/spice-gtk (master)

补充修改前一次提交

git commit --amend # 比如前次commit少提交了文件,可以使用git add添加文件,然后使用此命令修改前一次提交

$ git add --all
$ git commit --amend
[master 10e69f0] template
Date: Thu Jul 14 10:51:17 2016 +0800
4 files changed, 21 insertions(+)
create mode 100644 .gitignore
create mode 100644 CMakeLists.txt
create mode 100644 README.md
create mode 100644 main.c

临时提交和恢复

git stash # 将改动放入缓存区

git stash pop # 取出缓存区存放的内容

打补丁

> git diff from-commit to-commit > diff.patch # 打包修改
> git apply diff.patch # 应用修改

Git提交与恢复的更多相关文章

  1. GIT仓库如何恢复到前一次提交

    GIT仓库如何恢复到前一次提交   通过使用Git版本恢复命令reset,可以回退版本.reset命令有3种方式: git reset –mixed:此为默认方式,不带任何参数的git reset,即 ...

  2. Git提交引用和引用日志

    转载自:https://github.com/geeeeeeeeek/git-recipes/wiki/5.5-Git%E6%8F%90%E4%BA%A4%E5%BC%95%E7%94%A8%E5%9 ...

  3. git学习四:eclipse使用git提交项目

    支持原创:http://blog.csdn.net/u014079773/article/details/51595127 准备工作: 目的:eclipse使用git提交本地项目,提交至远程githu ...

  4. git 签出(恢复)指定文件

    在项目开发中,偶尔会因为误删文件或其他原因需要从git仓库中恢复某些文件.此篇文章将介绍如何通过git从历史提交记录.分支记录恢复指定文件. 1. git checkout 说明:使用git chec ...

  5. git 提交解决冲突(转载)

    转载 git 提交解决冲突 http://www.cnblogs.com/qinbb/p/5972308.html   一:git命令在提交代码前,没有pull拉最新的代码,因此再次提交出现了冲突. ...

  6. eclipse使用git提交项目

    eclipse使用git提交项目有2种方式:一种是git命令窗口,另一种是eclipse自带git插件(跟svn插件一样使用) 一.使用git命令窗口提交项目 1.首先官网下载git并安装,然后配置用 ...

  7. Git 将代码恢复到一个历史的版本

    Git 将代码恢复到一个历史的版本 要把代码回到某个历史版本 比如 test有两种方法 暴力的方式 如果你的仓库是自己在用(不影响别人),那么你可以使用 git reset --hard <ta ...

  8. eclipse使用git提交本地项目,提交至远程github上

    准备工作: 目的:eclipse使用git提交本地项目,提交至远程github上 eclipse版本:eclipse4.5  64位 jdk版本:jdk-1.7 64位 项目类型:maven web项 ...

  9. eclipse中使用自带的git提交项目

    1.自带git插件进行配置我们的用户名和密码,即是自己github注册用户.windows--perferences--Team--Git--Configuration 2.eclipse生成SSH2 ...

随机推荐

  1. mybatis 执行查询时报错 【Error querying database. Cause: java.sql.SQLException: Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException: Cannot find class: 】

    org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.sql.SQLE ...

  2. java 线程 被相互排斥堵塞、检查中断演示样例解说----thinking java4

    package org.rui.thread.block; /** * 被相互排斥堵塞 就像在interrupting.java中看到的,假设你偿试着在一个对象上调用其synchronized方法, ...

  3. jxl java工具类,导出excel,导入数据库

    1: 引入jxl jar 我使用的为maven管理, <!--Excel工具--> <dependency> <groupId>net.sourceforge.je ...

  4. java集合讲解干货集

    文章都来自网络,收集后便于查阅. 1.Java 集合系列01之 总体框架 2.Java 集合系列02之 Collection架构 3.Java 集合系列03之 ArrayList详细介绍(源码解析)和 ...

  5. css浏览器兼容问题集锦

    表单按钮用input type=submit和a链接两者表现不一致的问题 表单的输入框.文本.验证码图片没有对齐 IE6/7中margin失效 IE6中margin双边距 1.问题: 表单按钮用inp ...

  6. ubuntu下安装redis以及redis客户端在mac下的使用

    ubuntu下安装redis http://blog.fens.me/linux-redis-install/ 此方式利用brew安装包去获取最新的rdm客户端 资源失效了 https://www.j ...

  7. CSS3 3D下拉折叠菜单

    在线演示 本地下载

  8. u盘安装debian 7(Wheezy) stabe

    将一个闲置u盘插入电脑usb口.从http://mirrors.sohu.com/debian-cd/7.4.0/amd64/iso-dvd/debian-7.4.0-amd64-DVD-1.iso ...

  9. SPOJ - PHRASES Relevant Phrases of Annihilation —— 后缀数组 出现于所有字符串中两次且不重叠的最长公共子串

    题目链接:https://vjudge.net/problem/SPOJ-PHRASES PHRASES - Relevant Phrases of Annihilation no tags  You ...

  10. React之jsx语法特性

    jsx 语法,直接可以在js中使用html标签. 还可以通过花括号的形式,在html标签中,写js表达式. <div> { 1 + 2 } hello,world! </div> ...