序号 | 功能 | 命令 | ||||||
1 | 单独使本地某个文件和远端一致 | git checkout -- file | ||||||
2 | 忽略文件权限比较 | git config core.fileMode false | ||||||
3 | 回退到某个版本 | git reset --hard log_num | ||||||
4 | merge | 当前分支是master $ git checkout master 把issueFix中的内容Merge进来: $ git merge issueFix | ||||||
5 | 新建和删除远程分支 |
| ||||||
6 | Git 用户配置 | config 配置有system级别 global(用户级别) 和local(当前仓库)三个 设置先从system-》global-》local 底层配置会覆盖顶层配置 分别使用--system/global/local 可以定位到配置文件 查看系统config
查看当前用户(global)配置
查看当前仓库配置信息
| ||||||
7 | 撤销add | git reset HEAD XXX/XXX/XXX.java 就是对某个文件进行撤销了 | ||||||
8 | git cherry-pick | 做法: git cherry-pick 20c2f506d 2633961a1
git cherry-pick 9ecb65a8939^..e0763002f7d [A,B]
注意点: Git cherry-pick merge 后可能会编译不过,比如你改了一个分支的一个函数的名称 你cherrypick到另一个分支 但是另一个分支由于开发任务 这个函数新增了几个调用的地方,你cherry-pick后这几个仍是老的没被改 就编译不过,gg了 | ||||||
9 | 假设你有3个commit如下: commit 3 其中最后一次提交commit 3是错误的,那么可以执行: git reset --hard HEAD~1 你会发现,HEAD is now at commit 2。 然后再使用git push --force将本次变更强行推送至服务器。这样在服务器上的最后一次错误提交也彻底消失了。 值得注意的是,这类操作比较比较危险,例如:在你的commit 3之后别人又提交了新的commit 4,那在你强制推送之后,那位仁兄的commit 4也跟着一起消失了。
| |||||||
10 | Git 库 比较时忽略文件权限 | 解决办法: git中可以加入忽略文件权限的配置,具体如下: $ git config core.filemode false 这样就设置了忽略文件权限。查看下配置: $ cat .git/config
这时候再更新代码就OK了。 | ||||||
11 | 1.重命名 git branch -m oldBranchName newBranchName 2.删除远程分支:git push origin :oldBranchName 3.将重命名过的分支提交:git push origin newBranchName
| |||||||
12 | 查看某人提交的日志 | git log --author=“author”
| ||||||
13 | linux上设置避免每次git push 都需要账号密码 |
[root@iZ25mi9h7ayZ ~]# git config --global credential.helper store
[user]
| ||||||
14 | clone分支 | git clone https://cnhzlpvbktmirror01.ecitele.com:8443/scm/ilptltvbbp01/npti/npti.src.git | ||||||
15 | 删除没有被跟踪的文件 git clean -df git clean -dn 这个命令可以看看有哪此文件和目录会被删
| 有时做Build会引入很多之前没加入.gitignore的文件。这时你不可能每个目录每个文件地去删。 你要做的,git都帮你做好了。 hyang0@positive$ git --version git version 1.7.4.1 git clean -df 可帮你搞定一切。 举例: git clean -dn 这个命令可以看看有哪此文件和目录会被删 git clean -f 只会删文件,不会删目录 hyang0@positive$ git status # On branch master # Changes not staged for commit: # (use "git add/rm <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # deleted: .gitignore # # Untracked files: # (use "git add <file>..." to include in what will be committed) # # COPYING # INSTALL # Makefile.in # aclocal.m4 # autom4te.cache/ # config.h.in # configure # depcomp # install-sh # missing no changes added to commit (use "git add" and/or "git commit -a") hyang0@positive$ git clean -dn Would remove COPYING Would remove INSTALL Would remove Makefile.in Would remove aclocal.m4 Would remove autom4te.cache/ Would remove config.h.in Would remove configure Would remove depcomp Would remove install-sh Would remove missing hyang0@positive$ git clean -df Removing COPYING Removing INSTALL Removing Makefile.in Removing aclocal.m4 Removing autom4te.cache/ Removing config.h.in Removing configure Removing depcomp Removing install-sh Removing missing hyang0@positive$ git status # On branch master # Changes not staged for commit: # (use "git add/rm <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # deleted: .gitignore # no changes added to commit (use "git add" and/or "git commit -a")
|