huixisheng / huixisheng.github.com

前端开发者说,记录前端的故事
http://huixisheng.github.io/
12 stars 3 forks source link

git操作常见问题汇总 #6

Closed huixisheng closed 7 years ago

huixisheng commented 8 years ago

git添加空目录

在空目录下建.gitignore 内容:

# 忽略所有文件
*
# 除了这个文件
!.gitignore

git忽略已经被提交的文件

直接rm 然后 git add .本地磁盘也会被删除。我们要的是删除版本库的文件,并忽略。使用如下方法处理:

忽略文件夹 git rm -r --cached cache/* 然后在 .gitignore忽略删除的文件。注意git rm --cached 删除的是追踪状态

git 忽略已经提交的文件的修改

git update-index --assume-unchanged .env 重置之前添加的忽略 git update-index --no-assume-unchanged .env

同步github fork原作者分支的修改

假设当前在fork hexo-theme-amazeuiclone fork后的分支的终端上:

git remote add remote-hexo https://github.com/huixisheng/hexo-theme-amazeui.git
git fetch remote-hexo
git merge remote-hexo/master

参考

执行git push origin :test-branch, 远程test-branch已经删除了,但本地还在,git branch -a还可以看到

error: unable to delete ‘test-branch’: remote ref does not exist
error: failed to push some refs to ‘git@github.com:huixisheng/huixisheng.github.com.git’
git remote update --prune

git 恢复单个文件的历史版本

首先查看该文件的历史版本信息:git log Default@2x.png 记录下需要恢复的commit版本号:如 9aa51d89799716aa68cff3f30c26f8815408e926 恢复该文件:git reset 9aa51d89799716aa68cff3f30c26f8815408e926 Default@2x.png 还需要执行git checkout Default@2x.png 提交git:git commit -m "回滚Default@2x.png的历史版本"

git 如何还原某个文件一文提到更加简单的方法

直接用 git-checkout 即可。理解起来稍微有点奇怪就是了。 $ git checkout ${commit} /path/to/file

huixisheng commented 8 years ago

http://huixisheng.github.io/git/

huixisheng commented 7 years ago

整理到https://huixisheng.github.io/git-problem/