Git在提交之前隐藏特定文件 [英] Git Stashing specific files before a commit

查看:1000
本文介绍了Git在提交之前隐藏特定文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定我要找的是 git-stash ,但这是我想要做的。



我有用于本地使用的配置文件。这些文件已经存在于Git中。
现在,如果我添加一个新功能(更改其他文件),我想存储我的配置并点击提交,只提交与我的新功能相关的文件。



如果我使用git-stash,它会存储所有内容。
如何隐藏我的配置文件(仅)?



谢谢

解决方案<

使用git-assume-status和git-unassume-status

使用git-assume-status和git-unassume-status

 #!/ usr / bin / env ruby​​ 

#用于忽略已修改的文件 - 例如配置文件

ret =%x {git status --porcelain}
files = ret.lines.map {| x | x.split [1]}

files.each do | file |
#使得文件能够抵抗git reset hard
%x {git update-index --skip-worktree#{file}}
%x {git update-index --assume-unchanged# {file}}
end

和git-unassume

 #!/ usr / bin / env bash 

#用于忽略已修改的文件 - 例如配置文件

cd .git
rm index
cd ..
git reset

通过这种方式,您可以修改配置文件,但会被status和其他git add命令忽略。
如果您改变了主意,您可以运行git-unassume


I'm not sure if what I'm looking for is a git-stash but here is what I want to do.

I have configuration files customized for local use. Those files already exist in Git. Now, if I add a new feature (change other files), I want to stash my config and hit commit and only commit the files related to my new feature.

If I use git-stash, it stashes everything. How can I stash my config files (only)?

Thanks

解决方案

This is late but I found a better solution (a few years ago).

Using git-assume-status and git-unassume-status

#!/usr/bin/env ruby

# used to ignore modified files -- e.g configuration files

ret=%x{git status --porcelain}
files=ret.lines.map { |x| x.split[1] }

files.each do |file|
  # makes files resistant to git reset hard
  %x{git update-index --skip-worktree #{file}}
  %x{git update-index --assume-unchanged #{file}}
end

and for git-unassume

#!/usr/bin/env bash

# used to ignore modified files -- e.g configuration files

cd .git
rm index
cd ..
git reset

This way you can have your configuration files modified but ignored by status and other git add commands. If you change your mind, you run git-unassume

这篇关于Git在提交之前隐藏特定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆