git遇到问题解决

序号

功能

命令

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

1

git config --system --list

查看当前用户(global)配置

1

git config --global  --list

 

查看当前仓库配置信息

1

git config --local  --list

 

From <https://www.cnblogs.com/merray/p/6006411.html>

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

git 怎样删除远程仓库的最近一次错误提交?

假设你有3个commit如下:

commit 3
commit 2
commit 1

其中最后一次提交commit 3是错误的,那么可以执行:

git reset --hard HEAD~1

你会发现,HEAD is now at commit 2。

然后再使用git push --force将本次变更强行推送至服务器。这样在服务器上的最后一次错误提交也彻底消失了。

值得注意的是,这类操作比较比较危险,例如:在你的commit 3之后别人又提交了新的commit 4,那在你强制推送之后,那位仁兄的commit 4也跟着一起消失了。

 

From <https://www.cnblogs.com/code1992/p/8974896.html>

10

Git 库 比较时忽略文件权限

解决办法:

git中可以加入忽略文件权限的配置,具体如下:

$ git config core.filemode false

这样就设置了忽略文件权限。查看下配置:

$ cat .git/config

 

 

这时候再更新代码就OK了。

11

git 重命名本地分支,并提交到远程

1.重命名 git branch -m oldBranchName newBranchName

2.删除远程分支:git push origin :oldBranchName 

3.将重命名过的分支提交:git push origin newBranchName

 

From <https://www.cnblogs.com/hechangshou/p/9008297.html>

12

查看某人提交的日志

git log --author=“author”

 

From <https://www.cnblogs.com/mkl34367803/p/9196600.html>

13

linux上设置避免每次git push 都需要账号密码

 

  • 先cd到根目录,执行git config --global credential.helper store命令

[root@iZ25mi9h7ayZ ~]# git config --global credential.helper store

  • 执行之后会在.gitconfig文件中多加红色字体项

[user]
        name = 天明
        email = xxxx@xxxx.com
[credential]
        helper = store

  • 之后cd到项目目录,执行git pull命令,会提示输入账号密码。输完这一次以后就不再需要,并且会在根目录生成一个.git-credentials文件

 

From <https://www.cnblogs.com/jieshendada/p/7851866.html>

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")

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值