代码改变世界

git相关使用技巧和问题 fatal: repository 'xxxx' not found

2015-11-16 12:50  youxin  阅读(986)  评论(0编辑  收藏  举报

本地有修改和提交,如何强制用远程的库更新更新。我尝试过用git pull -f,总是提示 You have not concluded your merge. (MERGE_HEAD exists)。

我需要放弃本地的修改,用远程的库的内容就可以,应该如何做?傻傻地办法就是用心的目录重新clone一个,正确的做法是什么?

 

 

正确的做法应该是:

git fetch --all
git reset --hard origin/master

git fetch 只是下载远程的库的内容,不做任何的合并.git reset 把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.

 

 

参考链接:

http://stackoverflow.com/questions/1125968/force-git-to-overwrite-local-files-on-pull

 

Git忽略规则及.gitignore规则不生效的解决办法

在git中如果想忽略掉某个文件,不让这个文件提交到版本库中,可以使用修改根目录中 .gitignore 文件的方法(如无,则需自己手工建立此文件)。这个文件每一行保存了一个匹配的规则例如:

# 此为注释 – 将被 Git 忽略
 
*.a       # 忽略所有 .a 结尾的文件
!lib.a    # 但 lib.a 除外
/TODO     # 仅仅忽略项目根目录下的 TODO 文件,不包括 subdir/TODO
build/    # 忽略 build/ 目录下的所有文件
doc/*.txt # 会忽略 doc/notes.txt 但不包括 doc/server/arch.txt
规则很简单,不做过多解释,但是有时候在项目开发过程中,突然心血来潮想把某些目录或文件加入忽略规则,按照上述方法定义后发现并未生效,原因是.gitignore只能忽略那些原来没有被track的文件,如果某些文件已经被纳入了版本管理中,则修改.gitignore是无效的。那么解决方法就是先把本地缓存删除(改变成未track状态),然后再提交:
git rm -r --cached .
git add .
git commit -m 'update .gitignore'
 
在 git add <somefile> 之后,有的时候提示用“git rm --cache”来unstage,有的时候却是提示用“git reset HEAD”。区别在哪?
一个回答:

git rm --cached <file> will completely remove the file's contents from the index. This means that on commit the file will be removed from the HEAD commit. (If the file was only added to the index and not yet tracked this is a "no-op".)

git reset -- <file> resets the contents of the file in the index to be the same as the head commit. This means that on commit no changes will be committed to the file. This operation is not valid if there is no tracked version of the file in the HEAD commit.

http://stackoverflow.com/questions/12661306/git-rm-cached-file-vs-git-reset-file

 

 

 

[git] warning: LF will be replaced by CRLF | fatal: CRLF would be replaced by LF

遇到这两个错误,是因为Git的换行符检查功能。
core.safecrlf


Git提供了一个换行符检查功能(core.safecrlf),可以在提交时检查文件是否混用了不同风格的换行符。这个功能的选项如下:

false - 不做任何检查
warn - 在提交时检查并警告
true - 在提交时检查,如果发现混用则拒绝提交
建议使用最严格的 true 选项。

core.autocrlf

假如你正在Windows上写程序,又或者你正在和其他人合作,他们在Windows上编程,而你却在其他系统上,在这些情况下,你可能会遇到行尾结束符问题。这是因为Windows使用回车和换行两个字符来结束一行,而Mac和Linux只使用换行一个字符。虽然这是小问题,但它会极大地扰乱跨平台协作。

Git可以在你提交时自动地把行结束符CRLF转换成LF,而在签出代码时把LF转换成CRLF。用core.autocrlf来打开此项功能,如果是在Windows系统上,把它设置成true,这样当签出代码时,LF会被转换成CRLF:

$ git config --global core.autocrlf true
Linux或Mac系统使用LF作为行结束符,因此你不想 Git 在签出文件时进行自动的转换;当一个以CRLF为行结束符的文件不小心被引入时你肯定想进行修正,把core.autocrlf设置成input来告诉 Git 在提交时把CRLF转换成LF,签出时不转换:

$ git config --global core.autocrlf input
这样会在Windows系统上的签出文件中保留CRLF,会在Mac和Linux系统上,包括仓库中保留LF。

如果你是Windows程序员,且正在开发仅运行在Windows上的项目,可以设置false取消此功能,把回车符记录在库中:

$ git config --global core.autocrlf false

 

 

Git 恢复本地误删的文件

 

  通过git进行代码管理的项目,如果在本地编辑的过程中误删了某些文件或者文件夹,可以通过git操作来复原。

Step 1: git status

  查看本地对改动的暂存记录。如下图所示,本人误删了文件夹“../Server”。

 

Step 2:git reset HEAD [ 被删除的文件或文件夹 ]

 

tep 3:git checkout  [ 被删除的文件或文件夹 ]

  以Server文件夹为例,需要先后执行:

  git reset HEAD ../Server

  git checkout ../Server

 

 

问题:git clone或git pull出现fatal: repository 'xxxx' not found

 在另外一台机子上可以,在这台机子上始终不行,版本库地址确认正确,为什么?

有时候使用Git命令"git clone [url]"将远程仓库中的代码爬取下来的时候系统会报错"fatal repository not found"。

出现这个错误的一个可能的原因是本地已存储的git账号密码与爬取仓库所属的账号密码不同。

 

 

git 使用全局记住用户名密码后是明文,有没有加密的方式

 

 
gitconfig--globalcredential.helperstore
使用这个会在当前用户根目录下创建一个.git-credentials的文件用于明文保存用户名密码及相关链接
请问有没有加密后保存的方式

OS X:
git config --global credential.helper osxkeychain
Windows:

There’s a tool named git-credential-winstore (available at http://gitcredentialstore.codeplex.com) to store these credentials in the Windows Credential Store.

Linux/Unix:

There’s a tool named git-credentialgnome-keyring (bundled with Git 1.8.0 and above) to store these credentials in the GNOME Keyring.