Git:我分支出的Change分支

时间:2019-08-16 00:15:17

标签: git branch git-branch branching-and-merging

对于一项新功能,我从当前的dev分支(不是master)在Git中创建了一个分支,并在本地实现了一些更改,但未提交。 然后我被束缚了,开发继续进行。我用作基础的分支现已关闭,并且有一个新分支。

如何更改功能分支,使其以新的dev分支为基础?

// e.g implementation with vectors. //
class Employee{
    public:
        Employee()=default;
        virtual void typeOf(){
            cout << "Employee" <<endl;
        };
};

class Manager: public Employee{
    public:
        Manager()=default;
        virtual void typeOf() override{
            cout << "Manager" <<endl;
        };
};

class Clerk: public Employee{
    public:
        Clerk()=default;
        virtual void typeOf()override{
            cout << "Clerk" <<endl;
        };
};


int main(int argc, char**args){
    unique_ptr<vector<Employee*>>emp{new vector<Employee*>({new Clerk{}, new Employee{}, new Manager{}})}; // all you needed to do is to make a pointer from "Employee" and that will Make derived classes available to you ;) //
    for(int i{0}; i<emp->size(); ++i){
        (emp->at(i))->typeOf(); //
    };
    return(const int&&)-1;
};

现在我想移动功能,因为它分支到了dev 2,然后提交了我的更改:

master --
     \-- dev 1
             \-- feature
     \-- dev 2

当然,也不会丢失其他人可能做出的提交。

2 个答案:

答案 0 :(得分:1)

您需要

    <script>
function saveAs(filename, allHtml) {
allHtml =  document.documentElement.outerHTML; 
var blob = new Blob([allHtml], {type: 'text/csv'});
if(window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveBlob(blob, filename);
}
else{
var elem = window.document.createElement('a');
elem.href = window.URL.createObjectURL(blob);
elem.download = filename;        
document.body.appendChild(elem);
elem.click();        
document.body.removeChild(elem);
}
}    
</script> 

(如果我没记错的话,您可能需要git rebase dev1 feature --onto dev2 ,但我不这样认为)。

答案 1 :(得分:1)

好像您必须将尚未提交的更改添加到dev2分支之上。如果我弄错了,请纠正我。

解决方案:

git stash save -u "My feature"     # stash all changes
git branch -d feature              # delete old feature branch
git checkout dev2
git branch -b feature              # create new feature branch
git stash apply                    # unstash all you changes