Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python sh命令中的变量与从文件中读取的变量不一致_Python_Git - Fatal编程技术网

Python sh命令中的变量与从文件中读取的变量不一致

Python sh命令中的变量与从文件中读取的变量不一致,python,git,Python,Git,我有一个问题,使用带有git的sh模块获得的字符串与写入文件的字符串不匹配 我得到如下提交字符串 from sh import stat, git repo = git.bake(_cwd=git_dir) current_commit=git.log("-n1", "--format='%T'", git_file) print current_commit '89a848eb9ea98bfd6770301dce848052ec8ef63f' type(current_commit) &l

我有一个问题,使用带有git的sh模块获得的字符串与写入文件的字符串不匹配

我得到如下提交字符串

from sh import stat, git
repo = git.bake(_cwd=git_dir)
current_commit=git.log("-n1", "--format='%T'", git_file)
print current_commit
'89a848eb9ea98bfd6770301dce848052ec8ef63f'
type(current_commit)
<class 'sh.RunningCommand'>
with open(commit_store_file, 'w+') as f:
        f.write(str(current_commit))
当前的_commit显示如下

from sh import stat, git
repo = git.bake(_cwd=git_dir)
current_commit=git.log("-n1", "--format='%T'", git_file)
print current_commit
'89a848eb9ea98bfd6770301dce848052ec8ef63f'
type(current_commit)
<class 'sh.RunningCommand'>
with open(commit_store_file, 'w+') as f:
        f.write(str(current_commit))
类型如下

from sh import stat, git
repo = git.bake(_cwd=git_dir)
current_commit=git.log("-n1", "--format='%T'", git_file)
print current_commit
'89a848eb9ea98bfd6770301dce848052ec8ef63f'
type(current_commit)
<class 'sh.RunningCommand'>
with open(commit_store_file, 'w+') as f:
        f.write(str(current_commit))
当前的_提交被写入一个文件,如下所示

from sh import stat, git
repo = git.bake(_cwd=git_dir)
current_commit=git.log("-n1", "--format='%T'", git_file)
print current_commit
'89a848eb9ea98bfd6770301dce848052ec8ef63f'
type(current_commit)
<class 'sh.RunningCommand'>
with open(commit_store_file, 'w+') as f:
        f.write(str(current_commit))
当我用vi打开这个文件时,我看到了以下内容

^[[?1h^[=^M'89a848eb9ea98bfd6770301dce848052ec8ef63f'^[[m
^M^[[K^[[?1l^[>
with open(commit_store_file, 'r+') as f:
    stored_commit = f.readline()
我把它和下面的内容一起读了回来

^[[?1h^[=^M'89a848eb9ea98bfd6770301dce848052ec8ef63f'^[[m
^M^[[K^[[?1l^[>
with open(commit_store_file, 'r+') as f:
    stored_commit = f.readline()
这里的类型是string

type(stored_commit)
<type 'str'>
如何使用sh检索实际字符串并正确存储以使它们匹配


谢谢

这些角色对我来说就像寻呼机一样

尝试在命令前面添加
--无寻呼机

    git --no-pager log -n 1 --format='%T' --color=never
该选项需要在
log
命令之前,而不是之后,因此您必须
bake
将其放入。获得相同效果的另一种方法是使用
GIT_PAGER
环境变量或配置设置


获取机器可读树散列的另一种方法是
git cat file-p HEAD
。树将出现在输出的第一行,前缀为“tree”。

这些字符在我看来就像寻呼机一样

尝试在命令前面添加
--无寻呼机

    git --no-pager log -n 1 --format='%T' --color=never
该选项需要在
log
命令之前,而不是之后,因此您必须
bake
将其放入。获得相同效果的另一种方法是使用
GIT_PAGER
环境变量或配置设置


获取机器可读树散列的另一种方法是
git cat file-p HEAD
。树将出现在输出的第一行,前缀为“tree”。

我不熟悉
sh
,因此我无法帮助解决它,但在我看来,您的
str(当前提交)
中包含ansi颜色代码。你可以试着告诉git命令不要使用颜色,看看这个帮助我是否不熟悉
sh
,因此我无法帮助解决它,但在我看来,你的
str(current\u commit)
中有ansi颜色代码。您可以尝试告诉git命令不要使用颜色,看看这是否有帮助