git常用命令

来源:互联网 发布:网络连接错误711 编辑:程序博客网 时间:2024/06/08 11:01

1. 参考资料

git联机帮助,Version Control with GIT

2. git tag

帮助中给出的语法是:
git tag [-a | -s | -u <keyid>] [-f] [-m <msg> | -F <file>]<tagname> [<commit> | <object>]git tag -d <tagname>…​git tag [-n[<num>]] -l [--contains <commit>] [--points-at <object>][--column[=<options>] | --no-column] [--create-reflog] [<pattern>…​]git tag -v <tagname>…​


常用的几个:
打标签的例子:
$ git tag -m "Tag version 1.0" V1.0 3ede462

查看标签:git tag

删除标签:git tag -d tagname

提交到远程库:git push origin --tags


3. 删除文件&目录


git rm a.txt

git rm -r ./abc/

git rm -rf ./abc/


4. 删除不属于git库的文件或目录


git clean -dxf: 清除git库下面相对于库本身多出的文件或目录


5. 增加文件

git add a.txt


6. 设置编辑器

export GIT_EDITOR=VI


7. 提交的时候指定模版

这个模版将用前面设置的编辑器打开

git commit -t ~/git_commit.template


8. 查看日志

git log --author=Joy

git log --author=Joy -p

git log a.java

git log --author=Joy a.java

git log --author=Joy -p a.java


9. git clone之后,回到指定的commit


git reset --hard commit_id

10. 分支

查看所有分支,即有哪些分支:

git branch

这个命令会列出所有的分支,且前面有*的表示当前使用的分支。


切换分支:

git checkout branch_name

切换到指定的分支


merge其他分支的内容:

假如有两个分支:master(缺省会有的分支),first_branch。然后在master分支上做了一些修改,commit&push到远程了。那么在checkout到first_branch之后,可以git merge master命令,把master上所有的修改同步到当前的分支上。即命令格式为:

git merge the_other_branch_name


push时指定分支名称:

通常都是git push origin master,即推送到主分支。——小项目通常如此。

在创建了新的分支之后,就可以推送到这个新分支上,从而不影响主分支。命令:

git push origin the_branch_name


10. 回退到某个版本

git reset --hard commit_id

用这个命令会把本地的修改全部删除掉,而变成commit_id的样子。但不允许远程git库。


11. warning: LF will be replaced by CRLF

git config --gobal core.autocrlf false


12. 其他

git clone ssh://127.0.0.1/test.git -b the_main_branch

git show commit_id

git status



0 0
原创粉丝点击