面试题答案
一键面试#!/bin/bash
# 切换到新分支,若分支不存在则创建
if git checkout -b feature-new; then
# 在新分支下创建新文件并写入内容
echo "New feature content" > new_file.txt
# 将新文件添加到暂存区
if git add new_file.txt; then
# 提交更改
if git commit -m "Add new file for feature"; then
# 切换回主分支
if git checkout master; then
echo "操作成功,已切换回主分支。"
else
echo "切换回主分支失败。"
fi
else
echo "提交失败。"
fi
else
echo "添加文件到暂存区失败。"
fi
else
echo "切换到新分支或创建新分支失败。"
fi