简体   繁体   English

如何在git分支中重新提交相同的更改

[英]How to re commit same changes in git branch

I am using git for a weeks now. 我现在使用git已有几个星期了。 I am working in a feature branch, sometimes when I push code into my branch it shows lot of conflicts with develop branch. 我在Feature分支中工作,有时当我将代码推送到我的分支中时,它显示出与developer分支的许多冲突。 so I this time I followed following steps to avoid unwanted conflicts and problems at work place :( 因此,这次我遵循以下步骤来避免工作场所发生不必要的冲突和问题:(

  1. git branch abc git分支abc

  2. git checkout abc git checkout abc

  3. did my work 做了我的工作
  4. git stash git stash
  5. git pull origin develop git pull起源开发
  6. got conflicts 有冲突
  7. Resolved conflicts and also git stash pop 解决的冲突以及git stash pop
  8. git commit-m'message' // Don't know how merging removed lines which are not part of conflict git commit-m'message'//不知道如何合并不冲突的已删除行
  9. git push origin git push起源

Now these step resulted in committing of 2 files, one in which I resolved conflicts and one in which I worked. 现在,这些步骤导致提交了2个文件,其中一个我解决了冲突,另一个我在其中工作。 Say File1 and File2 respectively. 分别说File1和File2。

Now I need to re push my code but only file2 ie one in which I worked not in which I did conflict resolving and all. 现在,我需要重新推送我的代码,而只重新推送file2,即我在其中工作而不在其中进行冲突解决的所有内容。

But git status will show nothing as I have already done all the committing and pushing. 但是git status不会显示任何内容,因为我已经完成了所有提交和推送。 Also during some of the auto-merging the necessary code is removed from File1. 同样,在某些自动合并过程中,必要的代码也会从File1中删除。 How to bring that back? 如何把它带回来?

Any help would be appreciated? 任何帮助,将不胜感激?

As I am still learning GIT so any explanation would help me and others. 由于我仍在学习GIT,因此任何解释都会对我和其他人有所帮助。

I am using BITBUCKET. 我正在使用BITBUCKET。

Thanks!! 谢谢!!

For #1 & #2: They can be combined -- git checkout -b abc 对于#1和#2:可以将它们组合在一起git checkout -b abc

For #4: Why did you stash? 对于#4:为什么要藏起来? I believe you should have committed your changes here. 我相信您应该在这里进行更改。

For #6: Conflicts where? 对于#6:冲突在哪里? On your newly created feature branch? 在您新创建的功能分支上? That shouldn't be possible. 那不可能。

A typical work-flow would be as follows: 典型的工作流程如下:

  1. Make sure the main branch (master, or developer, or whatever) is up-to-date. 确保主分支(master,developer或其他)是最新的。 I'll use master for this example. 在本示例中,我将使用master
    • git checkout master
    • git fetch
    • git rebase origin/master
  2. Create and checkout the feature branch 创建并签出功能分支
    • git checkout -b featureBranch
  3. Make changes 做出改变
  4. Commit changes to featureBranch (ideally, this will be done multiple times; not a single large commit) 提交对featureBranch的更改(理想情况下,将完成多次;而不是一次大的提交)
    • git add . # This is just one example; #这只是一个例子; add selectively, as-is appropriate 有选择地添加,视情况而定
    • git commit
  5. Push local featureBranch to the remote, for review or whatever 将本地功能分支推送到远程,以供查看或其他
    • git push origin featureBranch
  6. When ready (eg reviewed and approved), merge featureBranch to master 准备就绪(例如,已审核并批准)后,将featureBranch合并到母版
    1. Rebase featureBranch against the latest master 重新设置功能针对最新的母版进行 分支
      • git checkout featureBranch
      • git fetch
      • git rebase origin/master
    2. Make sure the master is up-to-date 确保母版是最新的
      • git checkout master
      • git rebase origin/master
    3. Merge 合并
      • git merge --no-fast-forward featureBranch

This workflow, via rebasing featureBranch before merging & using non-fast-forward merging, will result in a linear, yet delineated, history of master . 通过合并之前使用reBranch的基础分支功能以及使用非快进合并,此工作流将产生线性但已划定的master历史记录。

Good luck! 祝好运!

To extend previous answer, I would add: Git stash will save your changes in a "pocket" if they are not ready for a commit. 为了扩展先前的答案,我要补充:如果您的更改尚未准备好提交,那么Git stash会将您的更改保存在“口袋”中。 But your changes are ready, so it is not necessary. 但是您的更改已准备就绪,因此没有必要。

About your question in previous comment (I do not have enough reputation for answer you in a comment): git pull update your local repository and your working directory with the changes in the remote repository, is a shortcut for git fetch followed by git merge. 关于先前评论中的问题(我没有足够的声誉在评论中回答您):git pull使用远程存储库中的更改更新本地存储库和工作目录,是git fetch和git merge的快捷方式。 But, as git merge have some drawbacks about the history, could be useful to used git fetch + git rebase instead. 但是,由于git merge在历史记录方面有一些缺点,因此可以代替使用git fetch + git rebase有用。

Git rebase works locally, so it could be used in an homologous way to git merge, but not git pull!. Git rebase在本地工作,因此可以以类似的方式用于git merge,但不能用于git pull!。 Many answers will explain better than me about git rebase, I hope to help a little bit. 关于git rebase,许多答案将比我更好地解释,希望对您有所帮助。

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

相关问题 如何撤消提交并将更改提交到Git中的其他分支? - How to undo a commit and commit the changes into the other branch in Git? 如何在git的同一分支中跳转提交 - How to jump a commit in the same branch at git git:如何进行提交,以使当前分支与另一个分支相同? - git: how to do a commit so that the current branch is the same as another branch? git如何仅将一次提交中的新更改合并到另一个分支中? - git how to merge just the new changes in a single commit into another branch? Git:如何像将其与另一个分支合并一样提交更改? - Git: how to commit changes as if it were a merge with another branch? git:如何将更改添加并提交到一个远程分支,而不提交到另一个? - git: how to add and commit changes to one remote branch but not another? 如何将分离的HEAD中的更改提交到git中的新分支 - how to commit changes in detached HEAD to a new branch in git Gerrit提交在放弃的同一分支上进行更改 - Gerrit commit changes on same branch on abondoned commit 将 git 中的分支恢复为同一分支中的先前提交 - revert the branch in a git to the previous commit in the same branch 如何判断给定git分支的最后一次提交合并到另一个分支中,以查找对该分支所做的更改? - How to tell the last commit of a given git branch merged into another branch to find changes made on the branch?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM