前端本地build脚本,上传代码,并连上服务器拉取代码

sh脚本

# build本地代码
npm run build

read -r -p "确认本地push代码,并且服务器拉取代码? [Y/N] " input

case $input in
    [yY][eE][sS]|[yY])
		echo "Yes"
		;;

    [nN][oO]|[nN])
		echo "No"
        # 退出
        exit 1
        ;;

    *)
		echo "Invalid input..."
        # 退出
		exit 1
		;;
esac

# 继续
git add .
git commit -m "build"
git push

ssh -p user@remoteNode "cd /myProject; git pull"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用JGit可以很方便地实现从远程仓库拉取代码到本地并检查更新。下面是一个简单的示例代码: ```java import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.PullResult; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.storage.file.FileRepositoryBuilder; import java.io.File; import java.io.IOException; public class GitPullExample { public static void main(String[] args) throws IOException, GitAPIException { // 本地仓库路径 String localPath = "/path/to/local/repo"; // 远程仓库URL String remoteUrl = "https://github.com/user/repo.git"; // 打开本地仓库 FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repository = builder.setGitDir(new File(localPath + "/.git")) .readEnvironment() // 读取git相关环境变量 .findGitDir() // 查找git目录 .build(); // 拉取代码 Git git = new Git(repository); PullResult pullResult = git.pull().call(); // 检查更新 if (pullResult.isSuccessful()) { if (pullResult.getMergeResult() != null && !pullResult.getMergeResult().getMergeStatus().isSuccessful()) { System.out.println("代码更新失败!"); } else { System.out.println("代码更新成功!"); } } else { System.out.println("拉取代码失败!"); } // 关闭Git和Repository git.close(); repository.close(); } } ``` 这个示例代码中,我们首先通过`FileRepositoryBuilder`打开本地仓库,然后使用`Git.pull().call()`方法从远程仓库拉取代码拉取完成后,我们通过检查`PullResult`对象来判断是否更新成功。最后记得关闭Git和Repository对象。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值