git操作0409

git init
git add.
git commit -m "Initial commit"
git checkout 7890abc # 切换到旧版本代码(只读)
git checkout master # 切回最新版本

git checkout -b new_branch 789abcd # 或 git checkout -b new_branch HEAD~3 很重点

git reflog #查看操作记录
git branch <被删分支名> 7890abc
git fetch origin
git checkout -b <分支名> origin/<分支名>
git log --oneline # 查看提交历史
git revert HEAD~2
(撤销 B) A -> B -> C -> D -> E E 是撤销 B 的修改后的新提交
目标:撤销 HEAD~2 这个提交引入的变更(不是撤销最近的两次提交)。

假设当前提交历史为:A -> B -> C -> D (HEAD),则 HEAD~2 指向提交 B。
执行后,会生成一个新的提交 E,其内容是将提交 B 的变更反向应用(即撤销 B 的修改)。
提交历史变为:A -> B -> C -> D -> E (HEAD)。
适用场景:

需要撤销某个旧提交(如提交 B 引入了一个 Bug)。
团队协作时,已推送的提交不可用 reset,只能用 revert
git reset --hard HEAD~2 A -> B 代码完全回退到提交 B 的状态
git revert HEAD~2
git reset --hard HEAD~2

HEAD 表示当前最新的提交。
~2 表示向前回退 2 个提交(即丢弃最近的 2 次提交)。
例如,当前提交历史是 A <- B <- C (HEAD),执行后代码会回退到提交 A。
效果:
代码回退:将代码库(工作目录、暂存区、提交历史)强制重置到 HEAD~2 对应的提交

git reset --hard 7890abc
含义:
7890abc:
某个具体的提交哈希(Commit Hash),例如 7fa6cea 或 ebdeed8。
可以是任意历史提交的哈希(前 7 位即可)。
效果:
精准回退:将代码库强制重置到指定提交 7890abc 的状态。
提交历史变更:
如果 7890abc 是较早的提交(例如比当前提交早 5 次),则所有后续提交都会被丢弃。
例如,提交历史是 A <- B <- C <- D <- E (HEAD),执行 git reset --hard B 后,代码会回退到 B,且提交 C/D/E 会被丢弃。
适用场景:
需要回退到某个特定版本(例如测试某个旧版本的问题)。
4. 风险警告
–hard 是危险操作!
它会永久删除工作目录和暂存区的所有未提交修改,以及回退路径上的提交历史。
如果代码未备份(例如未推送到远程仓库),可能导致数据丢失!
补救措施(如果误操作):
如果刚刚执行了 git reset --hard,但终端未关闭:
用 git reflog 找到之前的提交哈希,再 git reset --hard <旧哈希> 恢复。
如果已关闭终端且未备份:
数据可能无法恢复(取决于 Git 的垃圾回收机制)。

(jizhi) (base) ljsang@user:~/demo_all/jizhi$ git log --oneline
7fa6cea (HEAD -> master) Refactor analysis mechanism to support asynchronous processing. Update DirectMechanismAnalyzer methods to be asynchronous, allowing concurrent analysis of documents. Modify API to utilize the updated analyzer and improve performance. Enhance logging for analysis tasks and results.
f40f314 Implement logging for API requests and analysis in the FastAPI application. Refactor the analysis mechanism to log request details, analysis start and completion times, and errors. Remove print statements and replace them with appropriate logging calls. Update the DirectMechanismAnalyzer to include logging for API calls and analysis results.
ebdeed8 Sure! Pl

---
  1. (HEAD -> master)
    HEAD:
    表示当前你所在的分支或提交位置。HEAD 是 Git 中的一个指针,指向你当前正在操作的提交(类似于“当前位置”的标记)。
    master:
    当前分支的名称(默认主分支)。HEAD -> master 表示你当前位于 master 分支的最新提交上。
  2. 7fa6cea、f40f314、ebdeed8
    这些是 提交哈希(Commit Hash),是 Git 为每个提交生成的唯一标识符。

作用:
用于唯一标识一个提交(例如回退版本、查看差异、合并代码时)。
由 40 位十六进制字符组成(如 7fa6cea… 是前 7 位的缩写,足够唯一标识)。
如何用:
查看提交详情:git show 7fa6cea
比较提交差异:git diff f40f314 ebdeed8

07-06 21:20:00.686 run_task [INFO] 执行任务前先重置计时器状态 07-06 21:20:00.686 run_task [INFO] --->> 当前使用的Agent发布版本为:2025.7.5,版本发布内容请关注readme.txt 07-06 21:20:00.686 run_task [INFO] --->> 收到任务下发,任务信息:{'blockFinishUrl': 'http://inner-api.tengwu.ias.huawei.com/api/testcase-execute/v2/testcase-block-result', 'blockId': '4906894170796785664', 'callbackDomain': 'https://apigw-cn-south.huawei.com/api/', 'customConfigParams': {'password': 'xxxxxx', 'tracemalloc': True, 'sysmonitor_collection': {'time': 60}, 'username': 'xxxxxx'}, 'enviParams': {}, 'environment': {'blockId': '4906894170796785664', 'envId': '0aab505dd5184039a86ba5461c00211c', 'envName': 'ICS_SMOKE-10.39.85.66', 'envStatus': '1', 'logicNetwork': 'ICS_SMOKE', 'teId': '10.39.85.66:8810', 'teIp': '10.39.85.66'}, 'environmentId': 'SDE-0aab505dd5184039a86ba5461c00211c', 'environmentName': 'ICS_SMOKE-10.39.85.66', 'execSource': 'failCase', 'executionUnitCustomConfig': {'creator': 'yWX1425008', 'name': 'IAS_车机_H97E_ATSID_1963', 'typeName': 'IAS_车机_H97E', 'extendField1': 'R12545271605', 'location': 'D18-4', 'id': '442c092b31194417a731a9ae841e75e5', 'sn': 'R12545271605', 'parameters': [{}], 'status': '1'}, 'executorAddr': '10.39.85.66:8810', 'failCaseReExecute': False, 'gitParams': {'gitBranch': 'br_ichu_rel', 'gitCommitId': '', 'gitGroup': '', 'gitManifest': 'c385.xml', 'gitPath': 'https://szv-open.codehub.huawei.com/TestCode/IAS/ICS/icsv100_changan_c385.git', 'gitScriptSource': 'gitmm'}, 'logicNetwork': 'ICS_SMOKE', 'originalRunTaskId': '5551183', 'product': '255947337', 'reportResultUrl': 'http://inner-api.tengwu.ias.huawei.com/api/testcase-execute/v2/testcase-result', 'roundNumber': 1, 'runTaskId': '5557083', 'singleCaseTimeout': 20000, 'softwarePackageParams': {'path': ''}, 'taskExector': 'zWX1425150', 'taskName': 'H97E__monkey', 'teIp': '10.39.85.66', 'testcaseList': [{'caseNetWork': '', 'extend': {'physicalAutoType': '', 'analyzedBy': '', 'NetworkScriptName': '', 'logicCaseOwner': '', 'rank': '3', 'physicalCaseOwner': '', 'physicalEnvtype': ''}, 'logPath': 'https://inner-api.tengwu.ias.huawei.com/vtest-log/logpath/202576/5557083/4906894136437047296/4906894170796785664/075o10jm0t0s8n5o', 'name': '整机monkey', 'number': 'TC_WDX_TF001_MOKEY001_001', 'otherLogPath': 'https://tengwu.ias.huawei.com/vtest-ics-log/icslogpath/202576/5557083/4906894136437047296/4906894170796785664/075o10jm0t0s8n5o', 'round': 1, 'type': 'TestCase', 'uri': '/071t0v9lp2kdj/077n10ae95hsj/074010jlvh929/074010jlvh93c/075o10jm0steilsd/075o10jm0stkrlth/075o10jm0stm9ltp/075o10jm0svcjm75/075o10jm0t0s8n5o/', 'version': '1'}], 'versionParams': {'bversion': 'ICHU 200.1144.170-1110500.18.B128', 'bversionUri': '/071t0v9lp2kdj/077n10ae95hsj/074010jlvh929/', 'cversion': 'ICHU 200.1144.0', 'cversionUri': '/071t0v9lp2kdj/077n10ae95hsj/'}, 'server_ready': False} 07-06 21:20:00.687 run_task [INFO] --->> 当前任务的id: 5557083 07-06 21:20:00.687 run_task [INFO] --->> 当前任务块的id: 4906894170796785664 07-06 21:20:00.687 run_task [INFO] --->> 当前任务块执行轮次: 1 07-06 21:20:00.687 run_task [INFO] --->> 检查任务是否有用例 07-06 21:20:00.687 run_task [INFO] --->> 共下发1条用例,用例类型:ICS,用例编号:['TC_WDX_TF001_MOKEY001_001'] 07-06 21:20:00.687 run_task [INFO] --->> 执行环境的设备是否正常 07-06 21:20:00.687 run_task [INFO] --->> 准备工程和资源 07-06 21:20:00.687 prepare_project_resource [INFO] 脚本来源配置信息:{'gitBranch': 'br_ichu_rel', 'gitCommitId': '', 'gitGroup': '', 'gitManifest': 'c385.xml', 'gitPath': 'https://szv-open.codehub.huawei.com/TestCode/IAS/ICS/icsv100_changan_c385.git', 'gitScriptSource': 'gitmm'} 07-06 21:20:00.687 git_mm_download_project [INFO] 通过git mm准备工程或资源,等待获取文件锁 07-06 21:20:00.703 find_repository_record [INFO] git-mm仓库地址:https://szv-open.codehub.huawei.com/TestCode/IAS/ICS/icsv100_changan_c385.git 07-06 21:20:00.703 find_repository_record [INFO] 查找仓库工作拷贝在本地的位置,请等候... 07-06 21:20:00.705 find_repository_record [INFO] 目录D:\Local\DeviceTest\20250528205032_c385发现下载记录,文件内容是'https://szv-open.codehub.huawei.com/TestCode/IAS/ICS/icsv100_changan_c385.git -b br_ichu_rel -m c385.xml' 07-06 21:20:00.705 find_repository_record [INFO] 目录D:\Local\DeviceTest\20250528205032_c385是仓库的工作拷贝 07-06 21:20:00.705 git_mm_download_project [INFO] git准备工程或资源,已获得文件锁 07-06 21:20:00.705 git_mm_download_project [INFO] 修改工作路径为:D:\Local\DeviceTest\20250528205032_c385 07-06 21:20:00.705 execute_command [INFO] execute command: git mm init -u https://szv-open.codehub.huawei.com/TestCode/IAS/ICS/icsv100_changan_c385.git -b br_ichu_rel -m c385.xml 07-06 21:20:03.980 execute_command [INFO] command's output: INFO: Start remote sync for objects of project: manifest manifest> Auto packing the repository in background for optimum performance. manifest> See "git help gc" for manual housekeeping. manifest> Nothing new to pack. manifest> warning: There are too many unreachable loose objects; run 'git prune' to remove them. INFO: manifest repository has been initialized in D:\Local\DeviceTest\20250528205032_c385 07-06 21:20:03.982 git_mm_download_project [INFO] 成功删除目录: D:\Local\DeviceTest\20250528205032_c385\icsv100_changan_c385 07-06 21:20:03.982 execute_command [INFO] execute command: git mm sync --force-sync -d 07-06 21:20:21.359 execute_command [INFO] command's output: git-mm version: 2.6.5.rc0 INFO: Start remote sync for objects of project: manifest manifest> Auto packing the repository in background for optimum performance. manifest> See "git help gc" for manual housekeeping. manifest> Nothing new to pack. manifest> warning: There are too many unreachable loose objects; run 'git prune' to remove them. INFO: local jobs num is 4, fetch jobs num is 4 Logon failed, use ctrl+c to cancel basic credential prompt. Logon failed, use ctrl+c to cancel basic credential prompt. Logon failed, use ctrl+c to cancel basic credential prompt. Logon failed, use ctrl+c to cancel basic credential prompt. INFO: Start remote sync for objects of project: TestCode/IAS/ICS/ats_framework INFO: Start remote sync for objects of project: TestCode/IAS/ICS/icsv100_changan_c385 INFO: Syncing working directory: icsv100_changan_c385 INFO: Syncing working directory: ats_framework ats_framework> CopyFile: project.config -> icsv100_changan_c385/project.config ats_framework> CopyFile: config/common-service.json -> icsv100_changan_c385/config/common-service.json ERROR: post update failed: failed to copy 'D:/Local/DeviceTest/20250528205032_c385/ats_framework/config/common-service.json' to 'D:/Local/DeviceTest/20250528205032_c385/icsv100_changan_c385/config/common-service.json' ERROR: icsv100_changan_c385> fatal: Unable to create 'D:/Local/DeviceTest/20250528205032_c385/.mm/projects/icsv100_changan_c385/TestCode/IAS/ICS/icsv100_changan_c385.git/index.lock': File exists. ERROR: icsv100_changan_c385> ERROR: icsv100_changan_c385> Another git process seems to be running in this repository, e.g. ERROR: icsv100_changan_c385> an editor opened by 'git commit'. Please make sure all processes ERROR: icsv100_changan_c385> are terminated then try again. If it still fails, a git process ERROR: icsv100_changan_c385> may have crashed in this repository earlier: ERROR: icsv100_changan_c385> remove the file manually to continue. icsv100_changan_c385 (TestCode/IAS/ICS/icsv100_changan_c385.git): icsv100_changan_c385> fatal: Unable to create 'D:/Local/DeviceTest/20250528205032_c385/.mm/projects/icsv100_changan_c385/TestCode/IAS/ICS/icsv100_changan_c385.git/index.lock': File exists. icsv100_changan_c385> icsv100_changan_c385> Another git process seems to be running in this repository, e.g. icsv100_changan_c385> an editor opened by 'git commit'. Please make sure all processes icsv100_changan_c385> are terminated then try again. If it still fails, a git process icsv100_changan_c385> may have crashed in this repository earlier: icsv100_changan_c385> remove the file manually to continue. ERROR: ERROR: Sync failed, try the following suggestions, fix errors and try 'git mm sync' again: ERROR: ERROR: step 1: run 'git mm status' to check if the working directories' status is ok ERROR: step 2: if 'step 1' doesn't help, run 'git mm sync <project>...' to check special project(s) 07-06 21:20:21.359 git_mm_download_project [INFO] 修改工作路径为:D:\DeviceTestTools\device-test-agent-windows-service 07-06 21:20:21.359 prepare_project_resource [INFO] self.project_path: 07-06 21:20:21.359 prepare_project_resource [INFO] --->> 准备工程和资源失败,失败原因如下 07-06 21:20:21.359 prepare_project_resource [ERROR] Agent-304, 本地工程路径不存在,可能是工程下载失败,请检查agent.log,路径: Traceback (most recent call last): File "D:\DeviceTestTools\device-tools-agent\agent\ticc\runner.py", line 1602, in prepare_project_resource raise AgentException(ErrorReason.NOT_FOUND_LOCAL_PATH % self.project_path) base.agent_adapter.AgentException: Agent-304, 本地工程路径不存在,可能是工程下载失败,请检查agent.log,路径: 07-06 21:20:21.365 uploadTestCaseResult [INFO] acquire lock 07-06 21:20:21.365 uploadTestCaseResult [INFO] 测试用例:TC_WDX_TF001_MOKEY001_001 07-06 21:20:21.365 uploadTestCaseResult [INFO] 执行结果:Blocked 07-06 21:20:21.365 uploadTestCaseResult [INFO] 失败原因:git mm下拉代码失败,请查看agent.log 07-06 21:20:21.366 notify_upload_log [INFO] D:\Local\ATLog\task_5557083\block_4906894170796785664_1\agent.log 路径是agent日志,不是用例日志。 07-06 21:20:21.366 _ticcReportCaseResult [INFO] ------------------------- uploadTestCaseResult Start 07-06 21:20:21.366 _ticcReportCaseResult [INFO] 上报用例的执行结果 07-06 21:20:21.371 _ticcReportCaseResult [INFO] upload result's url: https://apigw-cn-south.huawei.com/api/apigateway/tengwu/vtest/testcase-result 07-06 21:20:21.371 _ticcReportCaseResult [INFO] upload result's headers: {'request_id': '1751808021366'} 07-06 21:20:21.371 _ticcReportCaseResult [INFO] upload result's body: {'runTaskId': '5557083', 'blockId': '4906894170796785664', 'product': '255947337', 'number': 'TC_WDX_TF001_MOKEY001_001', 'startTime': 1751808021365, 'finishTime': 1751808021365, 'result': '4', 'resultInfo': 'git mm下拉代码失败,请查看agent.log', 'uri': '/071t0v9lp2kdj/077n10ae95hsj/074010jlvh929/074010jlvh93c/075o10jm0steilsd/075o10jm0stkrlth/075o10jm0stm9ltp/075o10jm0svcjm75/075o10jm0t0s8n5o/', 'localLogPath': 'D:\\Local\\ATLog\\task_5557083\\block_4906894170796785664_1\\agent.log', 'executeTeIp': '10.39.85.66'} 07-06 21:20:21.619 _ticcReportCaseResult [INFO] upload result's response: (200, {'Server': 'API-Gateway', 'Date': 'Sun, 06 Jul 2025 13:20:21 GMT', 'Content-Length': '0', 'Connection': 'keep-alive', 'Trace-Id': '1a1a7dcb868a41af89524be1f880b1c2', 'jalor-jwt-verify': 'true', 'Vary': 'Access-Control-Request-Headers', 'Gateway-Version': '6.6.8.0.RELEASE', 'Gateway-Env': 'tengwu-prod', 'Time-Trace': '755b8970-39707155,pro-gw(184.199/61738)-apig1-Route2-lb2-jwt3-server(211.85/63402-200)38-sum39', 'X-Server-Process-Time': '0.0409', 'X-Upstream-Process-Time': '0.0409', 'X-ALB-SERVER': 'ALB'}, '') 07-06 21:20:21.619 _ticcReportCaseResult [INFO] 成功上报用例的执行结果 07-06 21:20:21.619 _ticcReportCaseResult [INFO] 还有0条用例待上报 07-06 21:20:21.619 _ticcReportCaseResult [INFO] ------------------------- uploadTestCaseResult End 07-06 21:20:21.620 notify_upload_other_log [INFO] 上传的本地日志路径是:D:\Local\ATLog\task_5557083\block_4906894170796785664_1\agent.log\TC_WDX_TF001_MOKEY001_001 07-06 21:20:21.621 uploadTestCaseResult [INFO] 开启线程上传所有日志到NAS 07-06 21:20:21.621 notify_upload_other_log [INFO] D:\Local\ATLog\task_5557083\block_4906894170796785664_1\agent.log\TC_WDX_TF001_MOKEY001_001,路径在执行机上不存在 07-06 21:20:21.621 uploadTestCaseResult [INFO] release lock 07-06 21:20:24.622 _ticcReportExecutorEnd [INFO] wait for ics_tep check finished!!! 07-06 21:20:24.622 _ticcReportExecutorEnd [INFO] ABNORMAL DEVICES: [] 07-06 21:20:24.622 _ticcReportExecutorEnd [INFO] acquire lock 07-06 21:20:24.622 _ticcReportExecutorEnd [INFO] 最后一个用例的执行结果非PASS,再次检测设备状态,隔离异常设备 07-06 21:20:24.622 _ticcReportExecutorEnd [INFO] release lock 07-06 21:20:24.622 _ticcReportExecutorEnd [INFO] ------------------------- reportExecutorCmdEnd Start 07-06 21:20:24.834 _ticcReportExecutorEnd [INFO] report executor end's url: https://apigw-cn-south.huawei.com/api/apigateway/tengwu/vtest/testcase-block-result 07-06 21:20:24.834 _ticcReportExecutorEnd [INFO] report executor end's headers: {'request_id': '1751808024623'} 07-06 21:20:24.834 _ticcReportExecutorEnd [INFO] report executor end's body: {'runTaskId': '5557083', 'blockId': '4906894170796785664', 'environmentId': 'SDE-0aab505dd5184039a86ba5461c00211c', 'result': '0', 'failCaseReExecute': False} 07-06 21:20:24.834 _ticcReportExecutorEnd [INFO] response : (200, {'Server': 'API-Gateway', 'Date': 'Sun, 06 Jul 2025 13:20:24 GMT', 'Content-Length': '0', 'Connection': 'keep-alive', 'Trace-Id': '29cd44dfc67b460b9d6bc7984c82eecf', 'jalor-jwt-verify': 'true', 'Vary': 'Access-Control-Request-Headers', 'Gateway-Version': '6.6.8.0.RELEASE', 'Gateway-Env': 'tengwu-prod', 'Time-Trace': '0f66478d-39707301,pro-gw(184.199/61738)-apig1-Route1-lb2-jwt3-server(211.72/63402-200)8-sum8', 'X-Server-Process-Time': '0.0109', 'X-Upstream-Process-Time': '0.0099', 'X-ALB-SERVER': 'ALB'}, '') 07-06 21:20:24.834 _ticcReportExecutorEnd [INFO] ------------------------- reportExecutorCmdEnd End 07-06 21:20:24.834 _ticcReportExecutorEnd [INFO] ------------------------- 开始手动下发stop消息 07-06 21:20:24.834 _ticcReportExecutorEnd [INFO] 手动下发停止消息到flask's url: http://127.0.0.1:8810/api/agent/v1/testcase-block-deliver-stop 07-06 21:20:24.834 _ticcReportExecutorEnd [INFO] 手动下发停止消息到flask's headers: {'request_id': '1751808024835'} 07-06 21:20:24.834 _ticcReportExecutorEnd [INFO] 手动下发停止消息到flask's body: {'groupId': '10.39.85.66:8810', 'runTaskId': '5557083'}
07-07
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值