在 SVN 中,doingsvn update
将显示带有状态前缀的完整路径列表:
$ svn update
M foo/bar
U another/bar
Revision 123
Run Code Online (Sandbox Code Playgroud)
我需要得到这个更新列表来做一些后期处理工作。将SVN仓库转移到Git后,找不到获取更新列表的方法:
$ git pull
Updating 9607ca4..61584c3
Fast-forward
.gitignore | 1 +
uni/.gitignore | 1 +
uni/package/cooldeb/.gitignore | 1 +
uni/package/cooldeb/Makefile.am | 2 +-
uni/package/cooldeb/VERSION.av | 10 +-
uni/package/cooldeb/cideb | 10 +-
uni/package/cooldeb/cooldeb.sh | 2 +-
uni/package/cooldeb/newdeb | 53 +++-
...update-and-deb-redist => update-and-deb-redist} | 5 +-
uni/utils/2tree/{list2tree => 2tree} | 12 +-
uni/utils/2tree/ChangeLog | 4 +-
uni/utils/2tree/Makefile.am | 2 +-
Run Code Online (Sandbox Code Playgroud)
我可以将 Git 拉取状态列表转换为 SVN 的格式:
M .gitignore
M uni/.gitignore
M uni/package/cooldeb/.gitignore
M uni/package/cooldeb/Makefile.am
M uni/package/cooldeb/VERSION.av
M uni/package/cooldeb/cideb
M uni/package/cooldeb/cooldeb.sh
M uni/package/cooldeb/newdeb
M ...update-and-deb-redist => update-and-deb-redist}
M uni/utils/2tree/{list2tree => 2tree}
M uni/utils/2tree/ChangeLog
M uni/utils/2tree/Makefile.am
Run Code Online (Sandbox Code Playgroud)
但是,某些具有长路径名的条目会被缩写,例如uni/package/cooldeb/update-and-deb-redist
缩写为...update-and-deb-redist
。
我认为我可以直接用 Git 来做,也许我可以git pull
以特殊格式配置的输出。
任何的想法?
编辑
我想出了一个解决方案:
首先,将最后一次和当前提交保存到变量PREV
和NEXT
:
$ PREV=`git show --format=format:%H --summary | head -1`
$ git pull
$ NEXT=`git show --format=format:%H --summary | head -1`
Run Code Online (Sandbox Code Playgroud)
然后,使用特殊格式比较两次提交:
$ git diff --name-status $PREV $NEXT
Run Code Online (Sandbox Code Playgroud)
这将给出输出:
A .gitignore
M uni/.gitignore
A uni/package/cooldeb/.gitignore
M uni/package/cooldeb/Makefile.am
M uni/package/cooldeb/VERSION.av
M uni/package/cooldeb/cideb
M uni/package/cooldeb/cooldeb.sh
...
Run Code Online (Sandbox Code Playgroud)
这与 Subversion 的完全相同。
然后,在预览模式下也很容易:
$ PREV=`git show --format=format:%H --summary | head -1`
$ git stash
$ git pull
$ NEXT=`git show --format=format:%H --summary | head -1`
$ git diff --name-status $PREV $NEXT
$ git reset --hard $PREV
$ git stash pop
Run Code Online (Sandbox Code Playgroud)
第一个选项man git-pull
是:
--no-commit\n\n With --no-commit perform the merge but pretend the merge failed and\n do not autocommit, to give the user a chance to inspect and further\n tweak the merge result before committing.\n
Run Code Online (Sandbox Code Playgroud)\n\n所以使用git pull --no-commit
.
编辑:哎呀!这是行不通的。正如 \xe8\xb0\xa2\xe7\xbb\xa7\xe9\x9b\xb7 (问题的作者)指出的那样,git pull --no-commit
仍然会提交。我在用着git version 1.7.0.4
。
如果您不知道所引入的更改是什么,那么有一种方法可以返回:
\n\ngit branch bad-branch-1\ngit log # Find the point you want to restore to,\n # for example: 35da5f07ca2c5\n\ngit reset --hard 35da5f07ca2c5 # Rolls back history and files\n
Run Code Online (Sandbox Code Playgroud)\n
归档时间: |
|
查看次数: |
5182 次 |
最近记录: |