git pull / stash与git过滤器冲突

时间:2018-08-16 18:24:18

标签: git git-filter

这个问题是关于将git与nbstripout过滤器一起使用,它会在将其存储在git下之前从jupyter笔记本(JSON文件)中删除一些字段。当多个开发人员使用同一笔记本时,使用带出过滤器可最大程度地减少冲突。

因此回购配置以以下内容开头:

$ cat .git/config
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = git@github.com:stas00/fastai_v1.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master
[include]
        path = ../.gitconfig

$ cat .gitconfig
[filter "nbstripout"]
        clean = nbstripout
        smudge = cat
        required = true
[diff "ipynb"]
        textconv = nbstripout -t

$ cat .gitattributes
*.ipynb filter=nbstripout

*.ipynb diff=ipynb

git diffgit commit期间使用此配置,笔记本将通过过滤器运行,该过滤器会删除本地的json字段(例如单元格的execution_count),并且会因开发人员而异。 / p>

现在考虑正常情况,同一笔记本在上游和本地更换。尝试将本地存储库与上游同步失败:

$ git pull origin master
From github.com:stas00/fastai_v1
 * branch            master     -> FETCH_HEAD
Updating 1ea49ad..ae0ba93
error: Your local changes to the following files would be overwritten by merge:
        dev_nb/004_callbacks.ipynb
Please commit your changes or stash them before you merge.
Aborting

$ git diff dev_nb/004_callbacks.ipynb | wc -l
60

$ git stash
Saved working directory and index state WIP on pull-merge: 1ea49ad Console progress bar

$ git diff dev_nb/004_callbacks.ipynb | wc -l
0

$ git pull origin master
From github.com:stas00/fastai_v1
 * branch            master     -> FETCH_HEAD
Updating 1ea49ad..ae0ba93
error: Your local changes to the following files would be overwritten by merge:
        dev_nb/004_callbacks.ipynb
Please commit your changes or stash them before you merge.
Aborting

这不应该发生,因为git stash应该隐瞒了所有本地更改。我不太确定究竟会发生什么,但是我认为git stash也会通过过滤器运行,并且只会存储通过nbstripout过滤器显示的更改。因此,也许git stash并没有使文件进入预修改状态?但是,在禁用过滤器之后,git diff什么也不显示(并且在禁用之前也没有显示)。

换句话说,为什么git pull看到潜在冲突并且不会合并,即使git diff显示不存在本地更改(但实际上,它们确实存在,它们只是被剥离的更改)通过过滤器)。

至少我希望git diff会显示出禁用滤除器后的更改,但不会。

要使git stash; gist pull工作,我必须在运行git stash之前禁用过滤器。

$ nbstripout --uninstall

$ git stash
Saved working directory and index state WIP on pull-merge: 1ea49ad Console progress bar

$ git pull origin master
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (1/1), done.
remote: Total 3 (delta 2), reused 3 (delta 2), pack-reused 0
Unpacking objects: 100% (3/3), done.
From github.com:stas00/fastai_v1
 * branch            master     -> FETCH_HEAD
   1ea49ad..ae0ba93  master     -> origin/master
Updating 1ea49ad..ae0ba93
Fast-forward
 dev_nb/004_callbacks.ipynb | 1268 ----------------------------------------------------------------------------------------------------------------------------------------
 1 file changed, 1268 deletions(-)

现在我必须记住要重新启用过滤器:

$ nbstripout --install

是否有更好的工作流程,不需要禁用/启用过滤器才能工作?

0 个答案:

没有答案