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 # 应用修改
posted @ 2017-10-14 10:13  银魔术师  阅读(1112)  评论(0编辑  收藏  举报