如何使用提交版本更新本地路径?

时间:2017-03-07 15:34:26

标签: javascript git nodegit

我尝试将repo克隆到本地文件系统,然后检出特定的提交 这就是我所拥有的:

Git.Clone(GIT_REPO_URL, localPath, CLONE_OPTIONS).then((repo) => {
    return repo.getCommit(version).then((commit) => {
        // use the local tree
    });
}).catch((error) => {
    // handler clone failure
});

这克隆了repo就好了,但我最终得到的本地版本是master的当前头部而不是我签出的提交(version)。

如何更新本地树以匹配此提交?
感谢。

3 个答案:

答案 0 :(得分:3)

getCommit不会修改本地树;它只是在脚本中检索内存中的提交 ,这样您就可以在不修改本地树的情况下使用它。 (例如,如果您想要浏览git历史记录并进行一些分析,但是不需要实际更新本地树以访问文件本身,那么这将非常有用。)

要实际签出特定分支或提交,您希望使用checkoutBranchcheckoutRef函数,这些函数实际上会更新本地工作树。 (注意他们的描述是如何明确地这样说的,与getCommit不同,<html> <head> <title>User Registeration Using PHP & MySQL</title> <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" > <!-- Optional theme --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" > <link rel="stylesheet" href="styles.css" > <!-- Latest compiled and minified JavaScript --> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> </head> <?php $connection = mysqli_connect('localhost', 'root', 'password', 'login'); if (!$connection){ die("Database Connection Failed" . mysqli_error($connection)); } $select_db = mysqli_select_db($connection, 'test'); if (!$select_db){ die("Database Selection Failed" . mysqli_error($connection)); } // If the values are posted, insert them into the database. if (isset($_POST['username']) && isset($_POST['password'])){ $username = $_POST['username']; $email = $_POST['email']; $password = md5($_POST['password']); $query = "INSERT INTO `user` (username, password, email) VALUES ('$username', '$password', '$email')"; $result = mysqli_query($connection, $query); if($result){ $smsg = "User Created Successfully."; }else{ $fmsg ="User Registration Failed"; } } ?> <body> <div class="container"> <form class="form-signin" method="POST"> <?php if(isset($smsg)){ ?><div class="alert alert-success" role="alert"> <?php echo $smsg; ?> </div><?php } ?> <?php if(isset($fmsg)){ ?><div class="alert alert-danger" role="alert"> <?php echo $fmsg; ?> </div><?php } ?> <h2 class="form-signin-heading">Please Register</h2> <div class="input-group"> <span class="input-group-addon" id="basic-addon1">@</span> <input type="text" name="username" class="form-control" placeholder="Username" required> </div> <label for="inputEmail" class="sr-only">Email address</label> <input type="email" name="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus> <label for="inputPassword" class="sr-only">Password</label> <input type="password" name="password" id="inputPassword" class="form-control" placeholder="Password" required> <div class="checkbox"> <label> <input type="checkbox" value="remember-me"> Remember me </label> </div> <button class="btn btn-lg btn-primary btn-block" type="submit">Register</button> <a class="btn btn-lg btn-primary btn-block" href="login.php">Login</a> </form> </div> </body> </html> 并没有说它修改了工作三,因为它没有在行为上这样做。)

答案 1 :(得分:1)

如果要结帐随机提交,则需要使用Checkout.tree(*)功能。

var keyWordNL = $('input[name*="keyword-nl_NL"]');

keyWordNL.on('keyup', function(){
var keyWordNL = $('input[name*="keyword-nl_NL"]').val();
var editor2 =  $('#introduction-nl_NL').val();
  if(editor2.match(keyWordNL)) {
   console.log('success');
  } else {
   console.log('fail');
  }
});

您可能也可能不想分离var repository; NodeGit.Clone(GIT_REPO_URL, localPath, CLONE_OPTIONS) .then(function(repo) { repository = repo; return repo.getCommit(version); }) .then(function(commit) { return NodeGit.Checkout.tree(repository, commit, checkoutStrategy: git.Checkout.STRATEGY.FORCE }); }).catch((error) => { // handler clone failure });

编辑: 这将签出并将HEAD设置为有问题的提交。

HEAD

答案 2 :(得分:0)

我还没有设法让它发挥作用,而事实证明这太复杂了,无法让工作变得微不足道,我决定这样做:

import * as process from "child_process";

const command = `git clone ${ GIT_REPO_URL } ${ repoPath } && cd ${ repoPath } && git checkout ${ version }`;
process.exec(command, error => {
    ...
});