可靠地更新git工作副本

时间:2017-10-23 13:35:13

标签: git repository

我无法找到适合我的用例的答案,所以我希望有人之前已经做过这个并且有解决方案。

我打算使用git将更改部署到aws实例。例如,我使用master分支进行生产。我以为我找到了一个在任何情况下都能解决的解决方案,具体如下:

git fetch
git checkout -f origin/<branchname>
git pull origin <branchname>
git submodule update --init --recursive
git submodule update --recursive --remote
我认为这会妥善处理分离的头部状态。它似乎工作了一段时间,但最近的更新,它只是检查本地分支,并没有从远程拉变化。

所以基本要求是: 修复/解决分离头状态 更新/添加新的子模块

这里是在repo

上终端上面执行上述步骤的大部分输出
redacteduser@ip-redacted:/redacted$ git fetch
remote: Counting objects: 22, done.
remote: Compressing objects: 100% (22/22), done.
remote: Total 22 (delta 7), reused 0 (delta 0)
Unpacking objects: 100% (22/22), done.
From redacted:redacteduser/redactedrepo
   b1cceb5..ee34124  master     -> origin/master
   08ec66e..ee34124  development -> origin/development
Fetching submodule redacted/redactedsubmodule
remote: Counting objects: 34, done.
remote: Compressing objects: 100% (34/34), done.
remote: Total 34 (delta 27), reused 0 (delta 0)
Unpacking objects: 100% (34/34), done.
From redacted:redacteduser/redactedsubrepo
   4d52d03..7019d5a  master     -> origin/master
redacteduser@ip-redacted:/redacted$ git checkout -f origin/master
Note: checking out 'origin/master'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at ee34124... redactedcommitmessage
redacteduser@ip-redacted:/redacted$ git pull origin master
From redacted:redacteduser/redactedrepo
 * branch            master     -> FETCH_HEAD
Already up-to-date.
redacteduser@ip-redacted:/redacted$ git submodule update --init --recursive
Submodule path 'redacted/redactedsubmodule': checked out '7019d5a442cc5f69e99f3434de23a646c563589a'
redacteduser@ip-redacted:/redacted$ git submodule update --recursive --remote
<no output from this command>

没有任何事实表明它没有更新主分支上的新提交。然后我又跑了一些东西,如图所示

redacteduser@ip-redacted:/redacted$ git status
HEAD detached at origin/master
nothing to commit, working directory clean
redacteduser@ip-redacted:/redacted$ git checkout master
M       redacted/redactedsubmodule
Previous HEAD position was ee34124... redactedcommitmessage
Switched to branch 'master'
Your branch is behind 'origin/master' by 5 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)
redacteduser@ip-redacted:/redacted$ git pull
Updating b1cceb5..ee34124
Fast-forward
 redactedlistoffiles
 7 files changed, 94 insertions(+), 15 deletions(-)
 create mode 100644 redactedfile1
 create mode 100644 redactedfile2

所以repo仍然是5次提交,即使我使用了fetch,checkout和pull on the branch。我只需要重新排序命令或连续两次执行它们吗?我希望有人知道答案

提前致谢

1 个答案:

答案 0 :(得分:1)

你是一个独立的头,你不需要:

git fetch
git checkout <branchname>
git pull origin <branchname>

删除&#34; -f origin /&#34;来自您的结账命令