Git 配置学习

来源:互联网 发布:snmp trap 端口 编辑:程序博客网 时间:2024/06/05 14:12
Linux
输出到文件用>,如git help > test.txt
追加到文件用>>,如git help >> test.txt
参考http://blog.csdn.net/songyang516/article/details/6758256


推荐初学git的网站http://www.yiibai.com/git/git_push.html


git help 命令
usage: git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           [-c name=value] [--help]
           <command> [<args>]


The most commonly used git commands are:
   add        Add file contents to the index
   bisect     Find by binary search the change that introduced a bug//二分查找的方式找Bug
   branch     List, create, or delete branches
   checkout   Checkout a branch or paths to the working tree
   clone      Clone a repository into a new directory
   commit     Record changes to the repository
   diff       Show changes between commits, commit and working tree, etc
   fetch      Download objects and refs from another repository
   grep       Print lines matching a pattern
   init       Create an empty git repository or reinitialize an existing one
   log        Show commit logs
   merge      Join two or more development histories together
   mv         Move or rename a file, a directory, or a symlink
   pull       Fetch from and merge with another repository or a local branch
   push       Update remote refs along with associated objects
   rebase     Forward-port local commits to the updated upstream head
   reset      Reset current HEAD to the specified state
   rm         Remove files from the working tree and from the index
   show       Show various types of objects
   status     Show the working tree status
   tag        Create, list, delete or verify a tag object signed with GPG


See 'git help <command>' for more information on a specific command.


git bisect help命令


Usage: git bisect [help|start|bad|good|skip|next|reset|visualize|replay|log|run]


git bisect help
print this long help message.
git bisect start [--no-checkout] [<bad> [<good>...]] [--] [<pathspec>...]
reset bisect state and start bisection.
git bisect bad [<rev>]
mark <rev> a known-bad revision.
git bisect good [<rev>...]
mark <rev>... known-good revisions.
git bisect skip [(<rev>|<range>)...]
mark <rev>... untestable revisions.
git bisect next
find next bisection to test and check it out.
git bisect reset [<commit>]
finish bisection search and go back to commit.
git bisect visualize
show bisect status in gitk.
git bisect replay <logfile>
replay bisection log.
git bisect log
show bisect log.
git bisect run <cmd>...
use <cmd>... to automatically bisect.


Please use "git help bisect" to get the full man page.


git log命令常用
git log --no-merges  仅显示提交的历史,不显示merge的历史
git log v2.6.12.. code/device 显示 v2.6.12..版本之前,修改了code/device里面的文件提交历史
git log --follow builtin-rev-list.c 显示builtin-rev-list.c这个文件的修改历史,包括之前对该文件的重命名的历史
git log --branches --not --remotes=origin 产看本地已经commit,但是还未push到远程的分支
git log master --not --remotes=*/master 查看本地master分支上已经commit,单还未push到远程的分支
git log --name-status 在Log的每个提交历史下修改的文件清单
git log -p 每个提交历史下方显示具体的修改位置
git log --oneline  所有的log以单行显示(一行仅显示commit的注释)
git log --pretty=oneline 所有的log以单行显示(一行仅显示commit的注释)


git tag命令使用
git tag 显示所有tag(包括远程的tag)
git tag xxx 生成一个tag (建议tag打在提交的那个分支上)
git push origin tag xxx 将tag,push到远程的服务器
git tag -d xxx 删除本地tag
git push origin :refs/tags/xxx 删除远程tag


git status命令使用
git status 显示所有修改的文件
git status --ignored code/ 忽视其他文件的修改,仅显示code文件夹下方的子目录文件的修改


git show 命令使用
git show 显示最近一次Log的记录,并详细列出修改的地方
git show e234dy89s3s...  显示e234dy89s3s...这条提交历史所有修改的详细记录
git show s4w5d4d6w.. --oneline 仅以单行


git rm命令使用
git rm Documentation/\*.txt 将Documentation文件夹下面的所有txt文件从gittree中删除


git reset命令使用
作用:将当前分支回退到最后一个分支或者之前commit的某一个分支上
git reset [--hard|soft|mixed|merge|keep] [<commit>或HEAD]
git reset --hard s4e6d4..或者HEAD 完全回退到s4e6d4..或者HEAD,s4e6d4..之后的所有修改都将还原
git reset --soft(默认) s4e6d4..或者HEAD ,index和working directory中的内容不作任何改变,仅仅把HEAD指向s4e6d4..。
参考http://blog.csdn.net/hudashi/article/details/7664464


清除所有提交
git reset --HARD 回退到某个分支
git clean -df    清除本地的所有改动
git checkout .


如何用git生成patch包
git format-patch y6r8wy... 将这个提交的改动生成一个patch,patch文件位于当前目录下
将patch(补丁)重新打上
patch -p1 < 0001-Added-liuxingde-test.patch
注: 0001-Added-liuxingde-test.patch为想要打的补丁的名字。运行该命令需在git项目的相应目录下。
参考http://www.cnblogs.com/y041039/articles/2411600.html


git rebase 命令使用
用于把一个分支的修改合并到当前分支
参考http://blog.csdn.net/hudashi/article/details/7664631
在基于远程分支"origin",创建一个叫"mywork"的分支。
$ git checkout -b mywork origin


git push 命令使用
用于将本地修改推送到远程
参考http://www.yiibai.com/git/git_push.html
常用格式git push <远程主机名> <本地分支名>:<远程分支名>
首先切换到dbg_aaaa_modify_bb_20150416分支上
然后执行git push origin dbg_aaaa_modify_bb_20150416:submit_aaaa_modify_bb_20150416
git push origin master将本地的master分支推送到origin主机的master分支。如果后者不存在,则会被新建。
git push origin :master 相当于git push origin --delete master表示删除origin主机的master分支。
git push origin 将当前分支推送到origin主机的对应分支


git pull 命令使用
用于从远程拉取最新的代码
这一条命令相当于git fetch 和 git merge 两条命令一起用


git mv 命令使用
用于重命名文件夹或者文件或者一个快捷方式
git mv file_from file_to


git merge 命令使用
作用是把一个分支或或某个commit的修改合并现在的分支上
参考http://blog.csdn.net/hudashi/article/details/7664382
常用方式 git merge origin/submit_xxxx
merge时有冲突,只有解决冲突之后才能merge成功


git fetch
作用是从远程获取最新版本到本地,不会自动merge


git revert
参考http://blog.csdn.net/hudashi/article/details/7664460






git维护
git gc
压缩历史
git fsck 
运行一些仓库的一致性检查
参考http://blog.csdn.net/hudashi/article/details/7668795
http://blog.chinaunix.net/uid-26770731-id-3285880.html



0 0