12篇 git 相关的文章

git 找回已删除的文件

找出已删除文件的提交记录:

git rev-list -n 1 HEAD -- <file_path>

返回为commit id

使用提交记录ID检出文件, commit id后缀**^**:

git checkout <commit id>^ -- <file_path>

或者一行命令:

$file 是文件路径

git checkout $(git rev-list -n 1 HEAD -- "$file")^ -- "$file"
查看更多 ~

如何向git仓库中提交空目录

程序中如果引用了空目录,但git提交的代码没有,有时会发生异常。
空目录通常git提交时给忽略了。
有个办法提交空目录即:在每个空目录中新增一个文件.gitignore

# Ignore everything in this directory
*
# Except this file
!.gitignore

至于为什么git不能提交空目录原因如下:https://git.wiki.kernel.org/index.php/GitFaq#Can_I_add_empty_directories.3F

查看更多 ~

windows上git clone认证失败后无法再次认证

git clone的时候,填错密码,再次git clone也不会提示输密码,表现如下

$ git clone https://wwww.git www
Cloning into 'www'...
remote: Coding 提示: Authentication failed.
remote: 认证失败,请确认您输入了正确的账号密码。
fatal: Authentication failed for 'https://wwww.git/

原因是 windows将密码信息保存在本地。需要这样处理
Control Panel\All Control Panel Items\Credential Manager
控制面板 > 用户账户 > 管理你的凭据 > Windows凭据
在Windows Credentials中找到git地址,编辑密码即可。

查看更多 ~

git list CRLF line ending file in uncommited files

关于git的crlf提交有如下配置。

提交时转换为LF,检出时转换为CRLF
git config --global core.autocrlf true

提交时转换为LF,检出时不转换
git config --global core.autocrlf input

提交检出均不转换
git config --global core.autocrlf false

拒绝提交包含混合换行符的文件
git config --global core.safecrlf true

允许提交包含混合换行符的文件
git config --global core.safecrlf false

提交包含混合换行符的文件时给出警告
git config --global core.safecrlf warn

但是我本地采用了git config --global core.autocrlf input, 即提交和检出都不使用自动转换crlf。那么这个就需要保证自己提交文件时注意将换行改为LF。

git status -s|grep -v 'D '|awk '{print $2}'|xargs file|grep CRLF
这条命令是将未提交到本地的文件列出,排除已删除的,并且行结尾使用了CRLF的。

查看更多 ~

git export ?(git 导出)

实际上没有git export的命令,有也可能是第三方的。
那么这里有个git archive可以用作导出。

git archive [--format=<fmt>] [--list] [--prefix=<prefix>/] [<extra>]
	      [-o <file> | --output=<file>] [--worktree-attributes]
	      [--remote=<repo> [--exec=<git-upload-archive>]] <tree-ish>
	      [<path>…​]
查看更多 ~