我想用提交消息"first"和"second"来压缩两个最新的提交.首先我拉主人然后我使用命令
git rebase -i HEAD~2 master
Run Code Online (Sandbox Code Playgroud)
它向我展示了这样一个编辑器中的两个提交:
pick first
pick second
Run Code Online (Sandbox Code Playgroud)
然后我将此编辑器更改为:
pick first
squash second
Run Code Online (Sandbox Code Playgroud)
保存更改后,我收到此消息:
Successfully rebased and updated refs/heads/master.
Run Code Online (Sandbox Code Playgroud)
它确实改变了远程主人的任何东西.要应用这些更改,我使用该git push命令并收到以下错误:
To https://github.com/aneelatest/GITtest.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/test/GITtest.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' …Run Code Online (Sandbox Code Playgroud) 我想使用python在隐藏文件夹中创建和编写.txt文件.我正在使用此代码:
file_name="hi.txt"
temp_path = '~/.myfolder/docs/' + file_name
file = open(temp_path, 'w')
file.write('editing the file')
file.close()
print 'Execution completed.'
Run Code Online (Sandbox Code Playgroud)
其中〜/ .myfolder/docs /是一个隐藏文件夹.我收到错误:
Traceback (most recent call last):
File "test.py", line 3, in <module>
file = open(temp_path, 'w')
IOError: [Errno 2] No such file or directory: '~/.myfolder/docs/hi.txt'
Run Code Online (Sandbox Code Playgroud)
当我将文件保存在某个非隐藏文件夹中时,相同的代码可以正常工作.
任何想法为什么open()不适用于隐藏文件夹.
我正在用python编写代码。我有一个配置文件,其中包含以下数据:
[section1]
name=John
number=3
Run Code Online (Sandbox Code Playgroud)
我正在使用ConfigParser模块在此已存在的confg文件中添加另一部分,而不会覆盖它。但是当我使用下面的代码时:
config = ConfigParser.ConfigParser()
config.add_section('Section2')
config.set('Section2', 'name', 'Mary')
config.set('Section2', 'number', '6')
with open('~/test/config.conf', 'w') as configfile:
config.write(configfile)
Run Code Online (Sandbox Code Playgroud)
它会覆盖文件。我不想删除以前的数据。有什么办法可以我再增加一个部分?如果我首先尝试获取和写入前几节的数据,那么随着节数的增加,它将变得不整洁。
我使用下面的代码来保存一个html文件,其名称中包含一个时间戳:
import contextlib
import datetime
import urllib2
import lxml.html
import os
import os.path
timestamp=''
filename=''
for dirs, subdirs, files in os.walk("/home/test/Desktop/"):
for f in files:
if "_timestampedfile.html" in f.lower():
timestamp=f.split('_')[0]
filename=f
break
if timestamp is '':
timestamp=datetime.datetime.now()
with contextlib.closing(urllib2.urlopen(urllib2.Request(
"http://www.google.com",
headers={"If-Modified-Since": timestamp}))) as u:
if u.getcode() != 304:
myfile="/home/test/Desktop/"+str(datetime.datetime.now())+"_timestampedfile.html"
file(myfile, "w").write(urllib2.urlopen("http://www.google.com").read())
if os.path.isfile("/home/test/Desktop/"+filename):
os.remove("/home/test/Desktop/"+filename)
html = lxml.html.parse(myfile)
else:
html = lxml.html.parse("/home/test/Desktop/"+timestamp+"_timestampedfile.html")
links=html.xpath("//a/@href")
print u.getcode()
Run Code Online (Sandbox Code Playgroud)
当我每次从If-Modified-since标头获取代码200时运行此代码.我在哪里做错了?我的目标是保存和使用html文件,如果在上次访问后修改它,则应覆盖html文件.