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. BCH分叉是一次站队博弈

    BCH分叉在即,很多人说BCH本次分叉实质是大佬间的斗争,主要是本次BCH分叉主要分为两大派别: 一派以BCH用户量最大的客户端Bitcoin ABC开发组为主,要在11月15日展开硬分叉升级,主要升 ...

  2. HDU - 1541 Stars 【树状数组】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1541 题意 求每个等级的星星有多少个 当前这个星星的左下角 有多少个 星星 它的等级就是多少 和它同一 ...

  3. 第13届景驰-埃森哲杯广东工业大学ACM程序设计大赛 G 旋转矩阵 【模拟】

    链接:https://www.nowcoder.com/acm/contest/90/G 来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536 ...

  4. Machine Learning No.8: Clusting

    1. K-means algorithm 2. K-means optimization objective 3. Random initialization

  5. Cmder配置

    中文乱码和重叠 当我们使用ls命令查看文件目录时,发现,中文被显示成了一些奇怪的乱码,将以下几行代码配置在cmder/config/user-aliases下即可解决问题: l=ls --show-c ...

  6. BZOJ 3037 创世纪

    题解: 首先从基环树上的环上选两个点x,y 断开x,y之间的边,然后做树形DP. 设f[x]为选x的情况下的最大值,g[x]为不选x的情况下的最大值. 分两种情况讨论, 1.选x,则y一开始就处于被支 ...

  7. wampserver发布详解

    以下为wampserver发布php并绑定域名的操作 1 在“httpd.conf”文件中查找:Include conf/extra/httpd-vhosts.conf,去掉前面的注释# 2 打开ap ...

  8. javscript 一些常用的工具方法

    一些工作中经常会用到的js代码,可以封装成一个工具库. 积少成多,从现在开始吧! -------------- 1 . 判断一段文字的长度.要求中文相当于2个字符,非中文的相当于1个字符 String ...

  9. Java如何创建内部类对象

    public static void main(String[] args) { Person p = new Test().new Person(); } class Person { String ...

  10. java-02 for循环,while循环

    ###############获取一个数字的每位数字############### #############1-100奇数和偶数和############## public class Sum { ...