git 问题之解决

Git Status 中文乱码解决

只要一行就行了

git config --global core.quotepath false

   
   
  1. 有这个时:~ (master|MERGING)  
  2. $ git reset --hard HEAD 即可解决
git remote -v 查看远程服务器地址和名称;
git remote show origin 查看远程服务器仓库状态
git br -v 查看各分支最后提交的信息
git br -r 查看远程分zhi
Git删除远程Tag、分支 删除远程分支 git branch -r -d origin/branch-name git push origin :branch-name 删除远程Tag 显示本地 tag git tag  Remote_Systems_Operation 删除本地tag git tag -d Remote_Systems_Operation  用push, 删除远程tag git push origin :refs/tags/Remote_Systems_Operation
如何创建.gitignore文件,忽略不必要提交的文件

Git Bash 进入命令行,进入项目所在目录。

 

2. 输入 touch .gitignore 在文件夹就生成了一个“.gitignore”文件。

然后在”.gitignore” 文件里输入你要忽略的文件夹及其文件就可以了。

 

3.然后用编辑器打开这个文件进行编辑就行了。

0.  git status
On branch master
Your branch and 'origin/master' have diverged,
and have 1 and 3 different commits each, respectively.
  (use "git pull" to merge the remote branch into yours)

这是分支产生了分叉现象(就是你的分支和服务器的对应分支有共同基点,然后向不同方向发展)

1. git pull
它包括了两个命令(git fetch; git merge)

Auto-merging a.c
CONFLICT (content): Merge conflict in a.c
Automatic merge failed; fix conflicts and then commit the result.

这是自动merge冲突产生了!

解决冲突方法:
A: git add a.c (直接编辑a.c文件, 然后git add a.c, 然后git ci )

a.c 冲突文件的冲突区域
1 111111111111
  2 222222222222
  3 <<<<<<< HEAD
  4 aaaaaaaaaaa
  5 =======
  6 bbbbbbbbbbbb
  7 >>>>>>> 064a9cbd32788b914965bc2e707b6485f354c2c0
  8 333333333333

064a9... 是要过来merge的分支, HEAD 就是当前分支的顶端了
====== 是各自的更改的分割线了

B: undo 这个 merge动作用如下命令

git merge --abort

协同开发时,我们从远程服务器上pull下代码的时候,出现以下提示信息:

Auto Merge Failed; Fix Conflicts and Then Commit the Result.


2.原因分析:


利用git status,输出如下:

root@hyk-virt:/etc# git status
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 2 and 2 different commits each, respectively.
#
# Unmerged paths:
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#    both modified:      apt/sources.list
#
# Changes 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:   cups/subscriptions.conf
#    modified:   cups/subscriptions.conf.O
#    modified:   mtab
#    modified:   update-manager/release-upgrades
#
no changes added to commit (use "git add" and/or "git commit -a")

从git status的结果可以发现:其中sources.list这个文件存在合并冲突

而进一步分析git pull的原理,实际上git pull是分了两步走的,(1)从远程pull下origin/master分支(2)将远程的origin/master分支与本地master分支进行合并

以上的错误,是出在了第二步骤


3.解决方法


方法一:如果我们确定远程的分支正好是我们需要的,而本地的分支上的修改比较陈旧或者不正确,那么可以直接丢弃本地分支内容,运行如下命令(看需要决定是否需要运行git fetch取得远程分支):

$:git reset --hard origin/master

或者$:git reset --hard ORIG_HEAD

解释:

 git-reset - Reset current HEAD to the specified state

--hard
               Resets the index and working tree. Any changes to tracked files
               in the working tree since <commit> are discarded.

方法二:我们不能丢弃本地修改,因为其中的某些内容的确是我们需要的,此时需要对unmerged的文件进行手动修改,删掉其中冲突的部分,然后运行如下命令

$:git add filename

$:git commit -m "message"


方法三:如果我们觉得合并以后的文件内容比价混乱,想要废弃这次合并,回到合并之前的状态,那么可以运行如下命令:

$:git reset --hard HEAD


 

git 删除导致本地和远程仓库不同步解决


使用git版本控制时,开始时对git不熟悉,导致了一些问题。

https://github.com/wolfpython/nids
比如在nids仓库中,开始新建了很多文档,但是后来发现很凌乱,删掉了不少:
$rm devdoc member_list 

本来在删除时,应尽量使用git rm命令来操作,但是如果不小心使用了rm命令,
导致本地仓库(master)和远程仓库(origin)不同步,怎么办?在这种情况下,
即使git commit -a 也是无济于事的。

先pull远程仓库,然后和本地仓库合并,最后提交即可。
$git pull origin 
$git merge origin master
$git push origin
 


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值