gpt4 book ai didi

Git推送到 checkout ?

转载 作者:太空狗 更新时间:2023-10-29 13:11:21 24 4
gpt4 key购买 nike

我想将我的文件直接推送到我的网络服务器。我将服务器添加为 testing 并尝试了

git push testing

但我得到 this error .制作裸存储库的解决方案有效,但我希望自动 check out 文件。我找到了这个 script但这并没有改变任何东西。

我可以将更改转移到第三个裸存储库,但这需要很长时间:

client:
git commit -m "test" -a
git push origin
<password>

server:
git pull origin/master

更新(二)

我在服务器上创建了一个新的分支git branch testing

我还在服务器上创建了 .git/hooks/post-update 添加了:

echo "a" >> /home/pi/log
git update-server-info
git stash
git merge testing >> /home/pi/log

在我运行的客户端上

git push testing HEAD:testing

现在我的 /home/pi/log 包含:

a
Updating ae2f44b..04753a9
Fast-forward
application/views/main/index.php | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

但是文件并没有改变。还有什么问题?

最佳答案

你现在怎么样"push-to-deploy" (git 2.4, May 2015) ,改进了 "push-to-checkout" (Git 2.3, February 2015) .

有关具体示例,请参见“Deploy a project using Git push”。

简而言之,您可以直接推送到 checkout 的分支(注意事项)。
参见 commit 4d7a5ce


更新:使用 Git 2.30(2021 年第一季度),您现在有一个示例“push-to-checkout” Hook ,其执行与内置默认操作相同的操作。

参见 commit e632c46 (2020 年 10 月 15 日)Adam Spiers (aspiers) .
(由 Junio C Hamano -- gitster -- merge 于 commit df7f850,2020 年 11 月 2 日)

hook: add sample template for push-to-checkout

Signed-off-by: Adam Spiers

The template is a more-or-less exact translation to shell of the C code for the default behaviour for git's push-to-checkout hook defined in the push_to_deploy() function in builtin/receive-pack.c, to serve as a convenient starting point for modification.

It also contains relevant text extracted from the git-config(1) and githooks(5) man pages.

即:

An example hook script to update a checked-out tree on a git push.

This hook is invoked by git-receive-pack when it reacts to git push and updates reference(s) in its repository, and when the push tries to update the branch that is currently checked out and the receive.denyCurrentBranch configuration variable is set to updateInstead.

By default, such a push is refused if the working tree and the indexof the remote repository has any difference from the currentlychecked out commit; when both the working tree and the index matchthe current commit, they are updated to match the newly pushed tipof the branch.

This hook is to be used to override the defaultbehaviour; however the code below reimplements the default behaviouras a starting point for convenient modification.

The hook receives the commit with which the tip of the currentbranch is going to be updated:

commit=$1

It can exit with a non-zero status to refuse the push (when it doesso, it must not modify the index or the working tree).

die () {
echo >&2 "$*"
exit 1
}

Or it can make any necessary changes to the working tree and to theindex to bring them to the desired state when the tip of the currentbranch is updated to the new commit, and exit with a zero status.

For example, the hook can simply run git read-tree -u -m HEAD "$1"in order to emulate git fetch that is run in the reverse directionwith git push, as the two-tree form of git read-tree -u -m isessentially the same as git switch or git checkout that switchesbranches while keeping the local changes in the working tree that donot interfere with the difference between the branches.

The below is a more-or-less exact translation to shell of the C codefor the default behaviour for git's push-to-checkout hook defined inthe push_to_deploy() function in builtin/receive-pack.c.

Note that the hook will be executed from the repository directory,not from the working tree, so if you want to perform operations onthe working tree, you will have to adapt your code accordingly, e.g.by adding "cd .." or using relative paths.

关于Git推送到 checkout ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9227282/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com