我对如何安全地将您的更改添加到Git感到有些困惑。我的程序如下。如果错误或需要修改,请告诉我:
毕竟我需要创建任何分支吗?那这个呢: (1)更新本地计算机中的代码 * git pull (2)进行更改,然后添加到分支分段 * git add * .txt& git commit - m" XYZ" (3)因为远程仓库中的代码可能自上次拉动后发生了变化,因此您的主机不是最新的: * git pull (4)将最新的主人与你的分支合并 * git merge (5)将您的更改提交给远程仓库 * git pull
答案 0 :(得分:1)
关闭,但有一些命令你正在做不必要的事情 - 比如重置。从您描述的工作流程来看,这通常是您要做的事情。
// this part creates a new branch from the most updated master
git fetch origin
git checkout master
git pull origin master
git checkout -b XYZ // creates a new branch XYZ
// do your work
// this part adds your files and commits to your XYZ branch
git add *file* // I recommend that you add files one at a time
git commit -m "My Commit Message" // the message doesn't have to have a connection to branch XYZ
// before you push up to origin again make sure your XYZ branch has the latest master code
git fetch origin
git pull origin master // fix any merge conflicts after this step
// push your XYZ branch up to origin
git push origin XYZ
// at this point there is usually some type of peer code review or QA process before any new changes are merged into master.
// Assuming, the branch and its changes are approved then you would merge to master like so:
git fetch origin
git checkout master
git pull origin master //sync master again in case there have been new changes
git merge XYZ
git push origin master
有人可能会说git fetch origin
命令对于此工作流程来说是多余的,但我认为让远程跟踪分支保持最新状态总是好的。
答案 1 :(得分:1)
这似乎非常过分,我不确定你为什么每次reset
。
我遵循的一般步骤是:
checkout
分支我想继续(pull
来确保它是最新的)pull
并合并任何更改add
更改为本地索引commit
本地更改push
更改为远程仓库