Git提交与恢复
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提交与恢复的更多相关文章
- GIT仓库如何恢复到前一次提交
GIT仓库如何恢复到前一次提交 通过使用Git版本恢复命令reset,可以回退版本.reset命令有3种方式: git reset –mixed:此为默认方式,不带任何参数的git reset,即 ...
- 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 ...
- git学习四:eclipse使用git提交项目
支持原创:http://blog.csdn.net/u014079773/article/details/51595127 准备工作: 目的:eclipse使用git提交本地项目,提交至远程githu ...
- git 签出(恢复)指定文件
在项目开发中,偶尔会因为误删文件或其他原因需要从git仓库中恢复某些文件.此篇文章将介绍如何通过git从历史提交记录.分支记录恢复指定文件. 1. git checkout 说明:使用git chec ...
- git 提交解决冲突(转载)
转载 git 提交解决冲突 http://www.cnblogs.com/qinbb/p/5972308.html 一:git命令在提交代码前,没有pull拉最新的代码,因此再次提交出现了冲突. ...
- eclipse使用git提交项目
eclipse使用git提交项目有2种方式:一种是git命令窗口,另一种是eclipse自带git插件(跟svn插件一样使用) 一.使用git命令窗口提交项目 1.首先官网下载git并安装,然后配置用 ...
- Git 将代码恢复到一个历史的版本
Git 将代码恢复到一个历史的版本 要把代码回到某个历史版本 比如 test有两种方法 暴力的方式 如果你的仓库是自己在用(不影响别人),那么你可以使用 git reset --hard <ta ...
- eclipse使用git提交本地项目,提交至远程github上
准备工作: 目的:eclipse使用git提交本地项目,提交至远程github上 eclipse版本:eclipse4.5 64位 jdk版本:jdk-1.7 64位 项目类型:maven web项 ...
- eclipse中使用自带的git提交项目
1.自带git插件进行配置我们的用户名和密码,即是自己github注册用户.windows--perferences--Team--Git--Configuration 2.eclipse生成SSH2 ...
随机推荐
- 洛谷 2261 [CQOI2007]余数求和
题目戳这里 一句话题意 求 \(\sum_{i=1}^{n} (k ~~\texttt{mod} ~~i)\) Solution 30分做法: 说实话并不知道怎么办. 60分做法: 很明显直接一遍o( ...
- Spring自定义配置--ConfigurationProperties
自定义配置的变量名: 在 *.properties 里面定义特定的变量 server.port=9000 amazon.associateId=habuma-20 建立Properties文件制定特定 ...
- 后缀自动机的python实现
#!/usr/bin/env python # -*- coding: utf-8 -*- # @Date : 2019-02-25 14:32:50 # @Author : Sheldon (thi ...
- API的理解和使用——哈希类型的命令
哈希常用的命令复习 命令 功能 hset key field value 设置哈希值 hsetnx 设置哈希值,field或键必须不存在 hget 获取某个file对应的值 hdel 删除一个或多个f ...
- IOS 十六进制字符串转换成UIColor
/** * 十六进制转换成UIColor * * @param stringToConvert 十六进制字符串 * * @return UIColor */ +(UIColor *) hexStrin ...
- Machine Learning No.4: Regularization
1. Underfit = High bias Overfit = High varience 2. Addressing overfitting: (1) reduce number of feat ...
- mysql优化之 EXPLAIN(一)
数据库优化最常用的命令就是用explain查看一下写的sql是否用到了索引: 如: (root@localhost) [akapp]>explain select * from sc_activ ...
- TCP/IP协议数据包文件PCAP分析器
一.设计原理 1.PCAP文件构成 参考http://blog.csdn.net/gulu_gulu_jp/article/details/50494909 PCAP文件由一个PCAP文件头和多个PC ...
- python处理txt文件的一种情况
在txt文本中,以换行符作为标记分段处理txt文件中的内容的方法: with open(path, 'r', encoding='utf-8') as f: for line in f: if lin ...
- 一个关于前端页面的小标签<tbody>
我们有时候希望将表格的内容分为多个模块,这时候就可以使用<tbody>标签,它是<table>的字标签,是<tr>的父标签,可以使用它达到一种设置样式的结果.