简体   繁体   English

GitHub版本控制无法正常工作

[英]GitHub version control not working as expected

Code at bottom 底部的代码

I am using a private repo on GitHub as a version control between me and a partner and I am having some difficulties in my approach. 我正在GitHub上使用一个私有存储库作为我和合作伙伴之间的版本控制,但是我的方法遇到了一些困难。 I have wrote a few bash scripts as a way of streamlining the process. 我已经写了一些bash脚本来简化流程。 Essentially I envisioned three bash scripts: get latest (GL), check-out (CKO), and commit (CM). 本质上,我设想了三种bash脚本:获取最新(GL),签出(CKO)和提交(CM)。 We have both set up a directory structure as such, usr/documents/opsys/ and initialized a git repo on our own separate machines in the same way. 我们都建立了目录结构,如usr/documents/opsys/并以相同的方式在我们自己的独立计算机上初始化了git repo。

cd usr/documents/opsys/
git init
git remote add origin https://YOURUSER:YOURPW@github.com/louis-krueger/OpSys.git
git pull origin master

My idea is to be able to log into our machine and run 我的想法是能够登录到我们的机器并运行

cd usr/documents/opsys/

After we are in the directory I intended for us to share/have in common. 进入目录后,我打算让我们共享/拥有共同之处。 Here we have the bash scripts in. Running ls returns the following: 这里有bash脚本。运行ls返回以下内容:

CKO  CM  GL  README.md  testkill  xinu-hw3

The idea worked, I was able to "GL", check out a working branch for my current work period, and then I could check in the changes to the branch when I was done. 这个想法行得通,我能够“ GL”,在当前工作期间签出一个工作分支,然后在完成后可以签入对分支的更改。 Then I manually merged my solo work, and deleted the dead branch. 然后,我手动合并了我的个人作品,并删除了无效分支。 This worked like I wanted it too until I tried showing my partner it. 在尝试向我的伙伴展示之前,它的工作方式就像我想要的一样。 I think the main issue is within my get latest. 我认为主要问题在于我的最新消息。 After we log in and switch our working directory to opsys/ we want to be able to run ./GL and anything in the directory which is not in the latest master commit should be deleted from the local machine and ls opsys/ should look exactly like what you would expect to get back from a theoretical "ls origin master" 登录并将工作目录切换到opsys/我们希望能够运行./GL,并且目录中所有不在最新master提交中的内容都应从本地计算机上删除,而ls opsys/应该看起来像您期望从理论上的“ ls起源大师”那里得到什么

CKO  CM  GL  README.md   xinu-hw3

I expected that testkill would have disappeared, but it didn't. 我以为testkill会消失,但是没有。

At the end of the day, ideally this would be my envisioned work flow (ASCII graphic) 归根结底,理想情况下这将是我设想的工作流程(ASCII图形)

Day 1
AM                         Noon                   3am(stuck here)

me             ----function1.c--------------------- 
              /
master ------/------------shared unmodified files-- 
                   \
partner             \ -------function2.c-----------


Day 2
        3am     morning  (**action here, see below)           

me      --(f1)---------------\ 
                              \
master  --unmodified common----|--all common---master--------- 
                              /
partner --(f2)---------------/

**action: After we have completed our separate work, I would like to be able to manually merge our branches back to the master so the next time we sign on we can ./GL and BAM we both see the same thing when GL checks out master. **操作:完成单独的工作后,我希望能够将分支手动合并回主服务器,以便下次登录时可以使用./GL和BAM,当GL检查时,我们都看到相同的内容高手。 Preferably both of the branches disappear(or is there a way to cut them down and store them behind the shed?...archive). 最好两个分支都消失(或是否有办法将它们剪下来并存储在棚屋后面?……存档)。

Needed (criticism && suggestions == true), it will be imperative that we have a quick way to share are work while working remotely from each other. 需要(批评和建议== true)时,当我们彼此之间远程工作时,我们必须有一种快速的方法来共享工作。

EOT EOT


code snippets 代码段

GL GL

#!/bin/bash
# @author Louis Krueger - 01/2016
#
# Get latest script
#

REMOTE_VERIFY="git remote -v"

echo "Git Latest"
echo "Please enter username:"
read user
if [ -n "$user" ]; then
        echo "enter pw:"
        read pw
else
        echo "username is nothing, exiting..."
        exit 1;
fi
if [ -n REMOTE_VERIFY ]; then
        git remote set-url origin https://$user:$pw@github.com/louis-krueger/Opsys.git
else
        git remote add origin https://$user:$pw@github.com/louis-krueger/OpSys.git
fi
git pull origin master
echo "$USER  up-to-date"

CKO 首席技术官

#!/bin/bash
# @author Louis Krueger - 01/2016
# Check out/create branch for current work
#


echo "Ready to work? Checking out branch"
echo "Please enter branch name:"
read branch
if [ -n "$branch" ]; then
        echo "creating branch!"
else
        echo "invalid branch name, exiting..."
        exit 1;
fi
git checkout -b $branch
git push origin $branch
echo "new branch ($branch) has been created"

CM 厘米

#!/bin/bash
# @author Louis Krueger - 01/2016
#
# Commit branch script
#
error="0"
echo "Are you sure you would like to commit and switch to master?(y/n)"
read confirm
if [ $confirm = "y" ]&&[ $error="0" ]; then
        echo "enter commit message:" 
        read message
        if [ -n "$message" ]&&[ $error="0" ]; then
                echo "enter branch name:"
                read branch
                if [ -n "$branch" ]; then
                        git pull
                        git add ./
                        git commit -m "$message"
                else
                        error="1"
                fi
        else
                error="1"
        fi
else
        error="1"
fi
if [ "$error" = "1" ]; then
        echo "You seem unsure Sire. Perhaps its time to get some fresh air... exiting. No changes have been made"
        exit 1;
fi
git push origin $branch
echo "switching to master"
git checkout master
echo "your branch ($branch) has been commited to the repo, contact admin for master&branch merge"

After we log in and switch our working directory to opsys/ we want to be able to run ./GL and anything in the directory which is not in the latest master commit should be deleted from the local machine... 登录并将工作目录切换到opsys/我们希望能够运行./GL,并且该目录中任何不在最新master提交中的内容都应从本地计算机上删除...

The commands to do this are: 执行此操作的命令是:

git fetch;
git reset --hard origin/master;

git fetch retrieves the latest copy of the repository from the remote, and git reset --hard origin/master resets all files in the repository to that state, destroying all changes. git fetch从远程检索存储库的最新副本,并且git reset --hard origin/master将存储库中的所有文件重置为该状态,破坏所有更改。

NB: This won't remove untracked files; 注意:这不会删除未跟踪的文件; to do that as well, add a rm -rf * before the git reset . 为此,在git reset之前添加rm -rf * If your repository contains dotfiles, you'll need to account for them in the rm command as well (remember not to delete .git !). 如果您的存储库包含点文件,则还需要在rm命令中说明它们(请注意不要删除.git !)。

Alternately, you could just rm opsys/ and git clone https://YOURUSER:YOURPW@github.com/louis-krueger/OpSys.git . 另外,您也可以rm opsys/git clone https://YOURUSER:YOURPW@github.com/louis-krueger/OpSys.git That would discard any local files and get you a fresh copy of the repository, but could be slow if your repository is large. 这将丢弃所有本地文件,并为您提供存储库的全新副本,但是如果您的存储库很大,则可能会很慢。


After we have completed our separate work, I would like to be able to manually merge our branches back to the master.... 在完成单独的工作之后,我希望能够手动将分支合并回主服务器。

Preferably both of the branches disappear... 最好两个分支都消失...

To merge your branch into master, just git checkout master then git merge branchname . 要将分支合并到master中,只需git checkout master然后git merge branchname You can then delete the local branch with git branch -d branchname . 然后,您可以使用git branch -d branchname删除本地分支。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM