使用git更正工作流程,以便比较不同的解决方案/实施

时间:2016-11-22 21:44:59

标签: git

最近我决定提高我的Python技能并开始解决Project Euler问题;另外,我想在这个项目中习惯使用git作为独奏用户。

这是我想用git实现的东西:

在我的project_euler文件夹中,我有名为001.py的Python文件等等,所以只是问题编号。正在“处理”的那些文件位于主文件夹中,一旦我更改了一些重要内容(但不一定能解决问题),我就会提交它们。

有两个子文件夹,working_solutionsoptimized_solutions。我会在文件工作后立即复制文件,即给出正确的解决方案 - 之后我希望有机会给我的实现提供一些想法,然后最终将优化的解决方案复制到后者中。

现在我想保留并比较解决方案的不同实现,而不必重命名文件001_algorithm1.py001_algorithm2.py等等 - 这对我来说似乎有点不对(毕竟,git应该采取照顾那些东西)。

另一方面,提交一个版本,尝试其他东西,然后提交第二个版本似乎是git方式 - 但这意味着每当我想比较时间时,例如,我必须在两个版本之间切换通过还原和提交,因为我没有本地可用的两种(或所有)不同的实现。

此设置是否正确分叉,但只有单个文件?

使用git时,上面提到的文件夹结构是否有意义?

我应该恰当地重命名文件,add并提交它们吗?

1 个答案:

答案 0 :(得分:1)

如何使用git分支?您可以根据模式// using static System.IO.Directory; SetCurrentDirectory(@"C:\Path\To"); ITypeLib typeLib = LoadTypeLibEx("C:\Path\To\Bar.tlb", REGKIND.REGKIND_NONE); 命名分支,例如$problemNumber-$algoNumber001_algo1等,然后当您想要比较两种方法时,您将执行以下操作:

001-algo2

所以步骤是:

git diff 001_algo1..001_algo2 -- optimized_solutions/001.py

更新:执行文件的两个版本作为python脚本

检查以下内容是否有效(至少在OSX上):

# Let's assume that you are on master branch and that optimized_solution does not have any solutions for problem 001
# (This creates and switches to that branch and is a combination of git branch 001_algo1 and git checkout 001_algo1)
git checkout -b 001_algo1

# Let's assume you have made your changes to the uber 001.py containing the solutions for problem 001 using algo1
git add optimized_solutions/001.py
git commit -m "Solutions for Prob 001 using algo1"

# Now switch to master and create the branch for the next algo
git checkout master
git checkout -b 001_algo2

# Make changes and commit
git add optimized_solutions/001.py
git commit -m "Solutions for Prob 001 using algo2"

# And finally when you want to compare
git diff 001_algo1..001_algo2 -- optimized_solutions/001.py

(请注意,在第二个命令中,只有在使用zsh时才需要some-git-repo - [master] » time python ./ex1.py Hello World! ./ex1.py 0.01s user 0.01s system 87% cpu 0.019 total some-git-repo - [master] » git show 001_algo2:ex1.py >! temp.py && time python ./temp.py Hello World in a branch!! python ./temp.py 0.01s user 0.01s system 87% cpu 0.020 total ,默认情况下,zsh设置为不破坏现有文件)

相关问题