[英]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 :( 因此,这次我遵循以下步骤来避免工作场所发生不必要的冲突和问题:(
git branch abc git分支abc
git checkout abc git checkout abc
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: 典型的工作流程如下:
git checkout master
git fetch
git rebase origin/master
git checkout -b featureBranch
git add .
# This is just one example; #这只是一个例子; add selectively, as-is appropriate 有选择地添加,视情况而定 git commit
git push origin featureBranch
git checkout featureBranch
git fetch
git rebase origin/master
git checkout master
git rebase origin/master
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.