GIT Tips (To be continued)

来源:互联网 发布:泰鲁斯·托马斯数据 编辑:程序博客网 时间:2024/05/18 13:29

1. 列出 git控制的文件:

git ls-tree -r master --name-only

2. 判断一个文件是否在git控制里:

git ls-files include/linux/list.h  --error-unmatchinclude/linux/list.h

$ touch new-file<pre name="code" class="plain">$ git ls-files new-file  --error-unmatcherror: pathspec 'new-file' did not match any file(s) known to git.Did you forget to 'git add'? 

或者:

$ git status  include/linux/list.hOn branch masternothing to commit, working directory clean
$ touch new-file$ git status  new-fileOn branch masterUntracked files:  (use "git add <file>..." to include in what will be committed)new-filenothing added to commit but untracked files present (use "git add" to track)
或者:

$ git status  --porcelain  new-file ?? new-file
3. 查找已经修改但是没有提交的文件

$ git checkout MMakefileMinclude/linux/memory.h
$ git status On branch masterChanges 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:   Makefilemodified:   include/linux/memory.hUntracked files:  (use "git add <file>..." to include in what will be committed)filenew-fileno changes added to commit (use "git add" and/or "git commit -a")

4. 显示对没提交的文件做的修改:

$ git diffdiff --git a/Makefile b/Makefileindex 256d744..3fdb0b9 100644--- a/Makefile+++ b/Makefile@@ -3,7 +3,8 @@ PATCHLEVEL = 10 SUBLEVEL = 28 EXTRAVERSION = NAME = TOSSUG Baby Fish-+11111+22222 # *DOCUMENTATION* # To see a list of typical targets execute "make help" # More info can be located in ./READMEdiff --git a/include/linux/memory.h b/include/linux/memory.hindex 85c31a8..c698b72 100644--- a/include/linux/memory.h+++ b/include/linux/memory.h@@ -19,7 +19,7 @@ #include <linux/compiler.h> #include <linux/mutex.h><pre name="code" class="plain">$ git checkout Makefile include/linux/memory.h

#include <linux/notifier.h>-+AAAAAAAAAAA #define MIN_MEMORY_BLOCK_SIZE (1UL << SECTION_SIZE_BITS) struct memory_block {

5. 撤销没有提交的修改:

$ git checkout MMakefileMinclude/linux/memory.h

$ git checkout Makefile include/linux/memory.h
$ git checkout $

6. 撤销提交操作:

    * git revert HEAD                  撤销前一次 commit
    * git revert HEAD^               撤销前前一次 commit
    * git revert commit-id

revert 会产生历史记录


7 git log

$ git log --pretty=oneline  --abbrev-commit22ee5b8 Revert "Revert "update Makefile with -gdwarf-2 -g3 flag""19f6c54 Revert "update Makefile with -gdwarf-2 -g3 flag"0178fc5 update Makefile with -gdwarf-2 -g3 flag9ad4424 intial kernel code


8change file permissions

git update-index --chmod=+x file


0 0
原创粉丝点击