Git rebase for a branch created days back

放肆的年华 提交于 2019-12-13 15:23:25

问题


I need help in understanding git rebase for this situation. I checked out a branch created by some one 10 days back. I checked out using

git checkout -b <some name> origin/branchname

(I just used different name to identify it)

After checkout, if I do rebase by being in this checked out branch,

git rebase origin/master

It shows some errors like 1) Trailing whitespace - I read about this but even after trying this command that I found online, i still see the warnings.

 git config core.whitespace nowarn

2) Auto-merging CONFLICT (add/add): Merge conflict in... these files are in master branch but the content is modified a little bit in the checkout branch. So how should I fix this? I don't have authority to change anything in master directly if that's the way to fix it. These files should have the content from this checkout branch so that the testing will work fine as it's related to that..please clarify me..

regards


回答1:


Guys have pretty much answered the question about whitespaces but didn't touch the rebase part of the question. Here is what's happening when you rebase:

first your checking out to some branch, then you say:

git rebase master

This means that you would like to rebase the current HEAD (your topic branch) onto master. Git is going back in history of your topic branch and in history of master branch and finds a commit that is a first common ancestor for both of them. This commit will be an old base for your topic branch. Then it takes all commits that happened since then in your branch and "reapplies" them in the order of appearance on top of the current master. Sometimes conflict can happen, then the rebase process stops and waits for your resolution. So you have have to manually resolve them by editing files and then marking them as resolved by git add conflicted_file When this is done you will have to say git rebase --continue

Now you're NOT changing files in master branch by doing that - the changes are happening in your topic branch and conflicts resolution are recorded in your topic branch.

hope that helps.




回答2:


If this is anything like question "git svn windows linux whitespace problems" that you mention, then the commands would be:

git config core.whitespace nowarn
git config core.autocrlf true

(to keep those settings locale to the current repo).
That would force all files to adopt one eol style, preventing a file on origin/master to have identical lines with a different eol that your own copy your are rebasing (which would explain the CONFLICTS (add/add) error messages).

But I remain dubious about autocrlf true, and prefer managing eol style through .gitattributes files.




回答3:


cd into the .git folder in your repo. You may not see this folder if you are using a files explorer that is not enabled to display hidden files or files with . or _ in the front. Inside the .git folder you will have a file named config. Open it up in a text editor and you should be able to see a portion named [core]. Add the whitespace = nowarn in there. The other location where you can find .gitconfig is under your home directory if you are using a linux machine. If its on windows it depends on how you installed git (via cygwin or msysgit).

If msysgit see this question (Where does git config --global get written to?) for the location of .gitconfig file. If its cygwin, then you can see its content by cat ~/.gitconfig.



来源:https://stackoverflow.com/questions/6665027/git-rebase-for-a-branch-created-days-back

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!