我经常发现自己在一个功能分支上,已经做出了改变。然后,我发现我必须做出改变,所以我:
memcpy(line, sline.c_str(), strlen(sline.c_str()))
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <unistd.h>
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include <sstream>
#define MAX_MSG 100
#define LINE_ARRAY_SIZE (MAX_MSG+1)
using namespace std;
int main()
{
int listenSocket, connectSocket, i;
unsigned short int listenPort;
socklen_t clientAddressLength;
struct sockaddr_in clientAddress, serverAddress;
char line[LINE_ARRAY_SIZE];
cout << "Enter port number to listen on (between 1500 and 65000): ";
cin >> listenPort;
listenSocket = socket(AF_INET, SOCK_STREAM, 0);
if (listenSocket < 0) {
cerr << "cannot create listen socket";
exit(1);
}
serverAddress.sin_family = AF_INET;
serverAddress.sin_addr.s_addr = htonl(INADDR_ANY);
serverAddress.sin_port = htons(listenPort);
if (bind(listenSocket, (struct sockaddr *) &serverAddress,
sizeof(serverAddress)) < 0) {
cerr << "cannot bind socket";
exit(1);
}
listen(listenSocket, 5);
while (1) {
cout << "Waiting for TCP connection on port " << listenPort << " ...\n";
clientAddressLength = sizeof(clientAddress);
connectSocket = accept(listenSocket, (struct sockaddr *) &clientAddress,
&clientAddressLength);
if (connectSocket < 0) {
cerr << "cannot accept connection ";
exit(1);
}
cout << " connected to " << inet_ntoa(clientAddress.sin_addr);
cout << ":" << ntohs(clientAddress.sin_port) << "\n";
memset(line, 0x0, LINE_ARRAY_SIZE);
while (recv(connectSocket,line, MAX_MSG, 0) > 0) {
cout << " -- " << line << "\n";
std::string delimiter[2];
int i = 0;
double cost = 0;
std::string carType;
std::string carStyling;
std::string sline;
sline = line;
stringstream ssin(sline);
while (ssin.good() && i < 2){
ssin >> delimiter[i];
++i;
}
sline = "";
for(i = 0; i < 2; i++){
cout << delimiter[i] << endl;
}
sline += "Your ";
carType = delimiter[0];
if(carType.compare("Sedan")==0){
sline += "Sedan";
cost = 100000;
}
else if(carType.compare("MPV")==0){
sline += "MPV";
cost = 120000;
}
else if(carType.compare("SUV")==0){
sline += "SUV";
cost = 140000;
}
else if(carType.compare("Luxury")==0){
sline += "Luxury";
cost = 180000;
}
carStyling = delimiter[1];
if(carStyling.compare("Sporty")==0){
sline += " Sporty ";
cost = cost * 1.5;
}
else if(carStyling.compare("Offroad")==0){
sline += " Offroad ";
cost = cost * 1.3;
}
sline += "will cost ";
std::ostringstream ss;
ss << cost;
sline += ss.str();
sline.copy(line, sline.length());
if (send(connectSocket, line, strlen(line) + 1, 0) < 0)
cerr << "Error: cannot send modified data";
memset(line, 0x0, LINE_ARRAY_SIZE); // set line to all zeroes
}
}
}
git add -A
重新调整更改并压缩最后两次提交,然后压缩最新提交,以便最终提交1次提交这是我经常使用的流程,但感觉非常麻烦和手动。有没有更聪明的方法,或者更常见的是为这种任务创建shell函数或别名?我说的是第2步到第4步。
答案 0 :(得分:3)
修改您刚刚对功能分支的HEAD进行的提交的最简单方法可能是修改提交通过:
git commit --amend 'your commit message here'
Git提交修改工作通过创建 new 提交,功能与旧提交相同,加上新的更改,然后用新的提交替换旧的HEAD提交。
请注意,这会重写历史记录,因此它不适合您已推送过的分支机构,而且已经被其他人拉过。但在这方面并不比你目前的改革方法更差。
作为重型rebase方法的替代方案,有一种更简单的方法来压缩分支的两个顶级提交。您可以执行软重置,然后执行提交:
git reset --soft HEAD~2
git commit -m 'made a small change to latest commit'
Git reset soft通过将HEAD指针移回两次提交(在本例中),同时保留工作目录和舞台原样。这具有基本上在第一次提交之前暂存在第一次提交中完成的工作以及第二次补丁提交的效果。然后,当你提交这项工作时,你将有效地将所有内容压缩到一次提交。
但是大多数时候我发现自己使用commit修改而不是reset soft来处理这种情况。