简体   繁体   English

SVN Changelist的Git是否等效?

[英]Git equivalence of SVN Changelist?

Just curious if Git has something like Subversions Changelist feature, its something that I find quite handy working with on the fly, I know I could run something like: 只是想知道Git是否具有Subversions Changelist功能之类的功能,我发现它可以随时随地使用,我知道我可以运行以下功能:

cat 'changelistfileimade' | xargs git update

but am curious if there's a built in method too? 但很好奇是否也有内置方法吗?

I googled around a bit more for this and I think I've found a replacement for the TortoiseSVN ignore-on-commit changelist use case I mention in my comment above. 我为此搜索了更多内容,我想我已经找到了我在上面的评论中提到的TortoiseSVN ignore-on-commit更改列表用例的替代品。 The command in question is git update-index --assume-unchanged <path/name> . 有问题的命令是git update-index --assume-unchanged <path/name> Git help has this to say about it: Git帮助有关于它的说法:

--[no-]assume-unchanged -[无]假设不变

When these flags are specified, the object names recorded for the paths are not updated. 指定这些标志时,为路径记录的对象名称不会更新。 Instead, these options set and unset the "assume unchanged" bit for the paths. 而是,这些选项设置和取消设置路径的“假定不变”位。 When the "assume unchanged" bit is on, Git stops checking the working tree files for possible modifications, so you need to manually unset the bit to tell Git when you change the working tree file. 当“假定未更改”位打开时,Git会停止检查工作树文件以进行可能的修改,因此您需要手动取消设置该位,以在更改工作树文件时告知Git。 This is sometimes helpful when working with a big project on a filesystem that has very slow lstat(2) system call (eg cifs). 当在lstat(2)系统调用非常慢的文件系统上处理大型项目(例如cifs)时,这有时会很有用。

This option can be also used as a coarse file-level mechanism to ignore uncommitted changes in tracked files (akin to what .gitignore does for untracked files). 此选项也可以用作粗略的文件级机制,以忽略跟踪文件中未提交的更改(类似于.gitignore对未跟踪文件所做的操作)。 Git will fail (gracefully) in case it needs to modify this file in the index eg when merging in a commit; 如果需要修改索引中的该文件(例如合并提交)时,Git将失败(正常)。 thus, in case the assumed-untracked file is changed upstream, you will need to handle the situation manually. 因此,如果假定未跟踪的文件在上游被更改,则您将需要手动处理这种情况。

I found an explanation of the option on Nick Quaranto's GitReady blog , which includes the following: 我在Nick Quaranto的GitReady博客上找到了对该选项的解释,其中包括以下内容:

Obviously there's quite a few caveats that come into play with this. 显然,对此有很多注意事项。 If you git add the file directly, it will be added to the index. 如果您直接git add文件,它将被添加到索引中。 Merging a commit with this flag on will cause the merge to fail gracefully so you can handle it manually. 合并带有此标志的提交将导致合并失败,因此您可以手动进行处理。

But that's only half the battle for me. 但这对我来说只是成功的一半。 The next step is knowing what you've ignored (and hopefully remembering why). 下一步是了解您已忽略的内容(并希望记住原因)。 That was provided by this handy comment by Abe Voelker on an aptly named question. 这是由安倍·沃克(Abe Voelker)在一个恰当命名的问题上的方便评论提供的。 Simply edit your .gitconfig file with the snippet 只需使用代码片段编辑.gitconfig文件

[alias]
    ignored = !git ls-files -v | grep "^[[:lower:]]"

Don't add the [alias] bit if it already exists in your file. 如果文件中已经存在[alias]位,请不要添加它。 And now git ignored will tell you something like this: 现在, git ignored会告诉您以下信息:

h configs/environment/local.php
h configs/logging/log4php.xml

You can take this a step further with aliases for ignore and unignore with the following lines: 您可以通过以下几行使用ignoreunignore ignore别名来更进一步:

    ignore = update-index --assume-unchanged
    unignore = update-index --no-assume-unchanged

I have never used SVN changelists myself, but if I understand correctly, it allows you to group files into changelists and later separately commit those changelists. 我自己从未使用过SVN变更列表 ,但是如果我理解正确,它可以让您将文件分组变更列表中 ,然后分别提交这些变更列表。 (Right?) (对?)

I don't think you really need such a feature with Git. 我认为您在Git中确实不需要这样的功能。 You can already separately stage ( git add ) each file or parts of it ( git add -p ) independently and commit those. 您已经可以分别git addgit add )每个文件或文件的一部分( git add -p )并提交它们。 You can create branches for each of your changelist, and later merge/rebase those branches. 您可以为每个变更列表创建分支,然后合并/重新设置这些分支。 Or you can create several commits and later re-order them with interactive rebase ( git rebase -i ). 或者,您可以创建多个提交,然后使用交互式rebase( git rebase -i )对它们进行重新排序。

Instead of svn diff --changelist something , you will simply use git show changelistbranch . 不用svn diff --changelist something ,您只需使用git show changelistbranch

You don't have to push those local/temporary branches. 您不必推那些本地/临时分支。 Nobody needs to see them, until you consider them ready to be released into the wild. 除非您考虑将它们准备发布到野外,否则没人需要看到它们。

You can even namespace your "changelist branches": git branch changelist/name_of_your_changelist , you will then have all changelists grouped by their prefix. 您甚至可以为“更改列表分支”命名空间: git branch changelist/name_of_your_changelist ,然后将所有更改列表按其前缀分组。

Am I missing something? 我想念什么吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM