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. JS表自动取值赋值

    /* * * V1.0.0 表单自动取值.赋值插件 * 表单类型:text radio select-one checkbox textarea * 注意项: * 1.表单必须设置name属性 * 调 ...

  2. MySQL——函数

    MySQL数据库提供了很多函数包括: (1)数学函数 (2)字符串函数 (3)日期和时间函数 (4)条件判断函数 (5)系统信息函数 (6)加密函数 (7)格式化函数 一.数学函数 数学函数主要用于处 ...

  3. linux撤销命令

    u撤销上一步操作 ctrl+r恢复上一步被撤销的操作

  4. 基于ajax和Form实现的注册

    注册 urls.py from django.contrib import admin from django.urls import path, re_path from app01 import ...

  5. gcc error - "iostream: No such file or directory"

    #include <iostream> using namespace std; int main(void) { cout<<"Hello World!\n&quo ...

  6. MSSQL2005外网IP的1433端口开启方法

    打开SQL Server Configuration Manager,在SQL server配置管理器展开SQL server 2005网络配置-->SQLEXPRESS 的协议-->双击 ...

  7. 《机器学习实战》学习笔记第二章 —— K-近邻算法

    主要内容: 一.算法概述 二.距离度量 三.k值的选择 四.分类决策规则 五.利用KNN对约会对象进行分类 六.利用KNN构建手写识别系统 七.KNN之线性扫描法的不足 八.KD树 一.算法概述 1. ...

  8. Module.exports和exports的区别

    原文链接: https://www.ycjcl.cc/2017/02/10/module-exportshe-exportsde-qu-bie/ 学习Seajs时,看到了exports.doSomet ...

  9. 让django完成翻译,迁移数据库模型

    声明:此Django分类下的教程是追梦人物所有,地址http://www.jianshu.com/u/f0c09f959299,本人写在此只是为了巩固复习使用 上篇我们完成了数据库模型的代码,但是还只 ...

  10. html5常用模板下载网站

    html5常用模板下载网站 开创者素材.站长素材.模板之家 推荐葡萄家园素材网,他们网页模板栏目有个HTML模板,很多静态源码.应该是你所需要的. html静态页面模板 还是服饰素材啊 朋友 设计云 ...