Git: How to checkout without removing exclusive files from current branch
Below is the tree of each branch I have in a git repo
[branch1]
+ boot
- cmdline.txt
- config.txt
+ etc
- fstab
[branch2]
+ etc
- passwd
- shadow
- group
when I checkout branch2
, files from branch1
are being removed from worktree and vice versa. How to checkout a branch without removing the exclusive files from the current branch?
git
add a comment |
Below is the tree of each branch I have in a git repo
[branch1]
+ boot
- cmdline.txt
- config.txt
+ etc
- fstab
[branch2]
+ etc
- passwd
- shadow
- group
when I checkout branch2
, files from branch1
are being removed from worktree and vice versa. How to checkout a branch without removing the exclusive files from the current branch?
git
1
Should probably just merge the 2 branches (maybe onto a third one). Otherwise something based offgit diff -p branch1..branch2 | patch
should work (am assuming your OS/toolkit has apatch
and so forth).
– Eugen Constantin Dinca
Nov 13 '18 at 12:43
add a comment |
Below is the tree of each branch I have in a git repo
[branch1]
+ boot
- cmdline.txt
- config.txt
+ etc
- fstab
[branch2]
+ etc
- passwd
- shadow
- group
when I checkout branch2
, files from branch1
are being removed from worktree and vice versa. How to checkout a branch without removing the exclusive files from the current branch?
git
Below is the tree of each branch I have in a git repo
[branch1]
+ boot
- cmdline.txt
- config.txt
+ etc
- fstab
[branch2]
+ etc
- passwd
- shadow
- group
when I checkout branch2
, files from branch1
are being removed from worktree and vice versa. How to checkout a branch without removing the exclusive files from the current branch?
git
git
edited Nov 13 '18 at 12:42
neckTwi
asked Nov 13 '18 at 12:29
neckTwineckTwi
82751740
82751740
1
Should probably just merge the 2 branches (maybe onto a third one). Otherwise something based offgit diff -p branch1..branch2 | patch
should work (am assuming your OS/toolkit has apatch
and so forth).
– Eugen Constantin Dinca
Nov 13 '18 at 12:43
add a comment |
1
Should probably just merge the 2 branches (maybe onto a third one). Otherwise something based offgit diff -p branch1..branch2 | patch
should work (am assuming your OS/toolkit has apatch
and so forth).
– Eugen Constantin Dinca
Nov 13 '18 at 12:43
1
1
Should probably just merge the 2 branches (maybe onto a third one). Otherwise something based off
git diff -p branch1..branch2 | patch
should work (am assuming your OS/toolkit has a patch
and so forth).– Eugen Constantin Dinca
Nov 13 '18 at 12:43
Should probably just merge the 2 branches (maybe onto a third one). Otherwise something based off
git diff -p branch1..branch2 | patch
should work (am assuming your OS/toolkit has a patch
and so forth).– Eugen Constantin Dinca
Nov 13 '18 at 12:43
add a comment |
3 Answers
3
active
oldest
votes
It's a normal feature.
You have to add your files and commit your initial branch:
git add .
git commit -m "hello dev of branch 1"
to go to next branch:
git checkout branch2
And merge your branch1
to branch2
:
git merge branch1
git merge branch1
just saysalready up to date
but nobranch1
files are added
– neckTwi
Nov 13 '18 at 13:04
Copy here all lines of your commands, please. Thegit merge branch1
have to be typed when you are in the branch2 (by thecheckout
command). In the branch1 it's normal to getalready up to date
.
– phili_b
Nov 13 '18 at 13:09
when I'm inbranch2
i didgit checkout -b branch3
and then didgit merge branch1
. butgit ls-files
show files only frombranch2
no files frombranch1
are present.
– neckTwi
Nov 13 '18 at 13:14
now I didgit checkout branch1
andgit merge branch2
. now,git ls-files
don't havebranch1
files!!
– neckTwi
Nov 13 '18 at 13:32
Before each checkout or merge you have to commit. Install TortoiseGit and look at its git commands.
– phili_b
Nov 13 '18 at 20:27
|
show 2 more comments
There isn't an easy way to do what you're describing, because it runs against the grain of git branches.
Branches in git are meant for tracking different lines of evolution of the same content. This isn't to say that it's the only possible use - git is very flexible - but that is the intent, and anything else may or may not be easy to do.
And in particular, switching back and forth between branches that contain different content, to keep the combined content on the work tree, is not something that's easy to do[1].
I recommend you take a step back and look at why you want one branch to have the password files, and another branch to have the boot directory and fstab. Understanding what problem you're trying to solve there, we might be able to suggest an alternative solution to that problem so that you can use git more in tune with its design.
At a bare minimum, to make what you're doing "work" (and I put "work" in quotes, because it's likely to have some quirky side-effects), you would probably want to:
- On each branch, add the files excluded from that branch to
.gitignore
- Before switching to a branch that includes files not on the current branch, you may have to remove the working copies of those files. (In the simple two-branch example, you might do this with
git clean -x
, but be aware this would also sweep up any other ignored working tree files - such as build artifacts that would then have to be regenerated.) - After switching to a branch that excludes files on the current branch, check those files out from the current branch (
git checkout HEAD@1 -- ets/fstab
and so on)
Honestly that doesn't sound like much fun for a "might work basically correctly most of the time" solution, which is why I recommend instead looking at why you have different files on different branches.
[1] That may seem weird, if you are used to tools that do use branches in that way. But if you look at the general case of branches as defined by git, you will realize there are good reasons why it doesn't want to make assumptions that would make this "easy".
I didn't read your answer initially because I didn't understand your lines:because it runs against the grain of git branches
,lines of evolution
. too dramatic you see? But after I've put my answer I've become curious to understand what you are trying to say; You said the same!
– neckTwi
Nov 14 '18 at 3:57
@neckTwi - No, in fact I don't see. There is nothing "dramatic" about those phrases, and they are pretty standard in expressing what I'm saying. Also, our answers definitely do not say the same thing, and in fact I think you might want to spend a little time better understanding git's branch model - because, for example, to say that branches have "ancestors" in git is incorrect.
– Mark Adelsberger
Nov 15 '18 at 0:43
I've corrected my phrase merging an ancestor has no effect. since a new branch being checked out have the same history as the current branch, doesn't it make the current branch an ancestor to the new branch?
– neckTwi
Nov 15 '18 at 16:57
@neckTwi : No. I wonder if I'm somehow not understanding your question, because it looks as though you just asked me whether something is true, that I had literally just said is not true...
– Mark Adelsberger
Nov 15 '18 at 18:23
add a comment |
Understand how Git works!
By default, every Git branch has an ancestor except the initial master branch which is an ancestor to all other branches. So if any branch has only exclusive files than any other branch then you should have deleted all the files from the branch initially and added some exclusive files to it.
So if the branch1
is an ancestor to branch2
and branch2
don't have the files of branch1
then branch2
is marked to not contain files of branch1
. So merging branch1
to branch2
will remove the files of branch1
in branch2
. Yes, merging an ancestor has no effect other than updating the changes of the ancestor.
Though one can git checkout --orphan NewOrphan
, It can't be merged with another branch with a different history (ancestor).
So the only way to do it is as @EugenConstantinDinca said in the comment. Or rethink what you are trying to achieve by not removing the files of the parent branch.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53281029%2fgit-how-to-checkout-without-removing-exclusive-files-from-current-branch%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
It's a normal feature.
You have to add your files and commit your initial branch:
git add .
git commit -m "hello dev of branch 1"
to go to next branch:
git checkout branch2
And merge your branch1
to branch2
:
git merge branch1
git merge branch1
just saysalready up to date
but nobranch1
files are added
– neckTwi
Nov 13 '18 at 13:04
Copy here all lines of your commands, please. Thegit merge branch1
have to be typed when you are in the branch2 (by thecheckout
command). In the branch1 it's normal to getalready up to date
.
– phili_b
Nov 13 '18 at 13:09
when I'm inbranch2
i didgit checkout -b branch3
and then didgit merge branch1
. butgit ls-files
show files only frombranch2
no files frombranch1
are present.
– neckTwi
Nov 13 '18 at 13:14
now I didgit checkout branch1
andgit merge branch2
. now,git ls-files
don't havebranch1
files!!
– neckTwi
Nov 13 '18 at 13:32
Before each checkout or merge you have to commit. Install TortoiseGit and look at its git commands.
– phili_b
Nov 13 '18 at 20:27
|
show 2 more comments
It's a normal feature.
You have to add your files and commit your initial branch:
git add .
git commit -m "hello dev of branch 1"
to go to next branch:
git checkout branch2
And merge your branch1
to branch2
:
git merge branch1
git merge branch1
just saysalready up to date
but nobranch1
files are added
– neckTwi
Nov 13 '18 at 13:04
Copy here all lines of your commands, please. Thegit merge branch1
have to be typed when you are in the branch2 (by thecheckout
command). In the branch1 it's normal to getalready up to date
.
– phili_b
Nov 13 '18 at 13:09
when I'm inbranch2
i didgit checkout -b branch3
and then didgit merge branch1
. butgit ls-files
show files only frombranch2
no files frombranch1
are present.
– neckTwi
Nov 13 '18 at 13:14
now I didgit checkout branch1
andgit merge branch2
. now,git ls-files
don't havebranch1
files!!
– neckTwi
Nov 13 '18 at 13:32
Before each checkout or merge you have to commit. Install TortoiseGit and look at its git commands.
– phili_b
Nov 13 '18 at 20:27
|
show 2 more comments
It's a normal feature.
You have to add your files and commit your initial branch:
git add .
git commit -m "hello dev of branch 1"
to go to next branch:
git checkout branch2
And merge your branch1
to branch2
:
git merge branch1
It's a normal feature.
You have to add your files and commit your initial branch:
git add .
git commit -m "hello dev of branch 1"
to go to next branch:
git checkout branch2
And merge your branch1
to branch2
:
git merge branch1
answered Nov 13 '18 at 12:48
phili_bphili_b
8611
8611
git merge branch1
just saysalready up to date
but nobranch1
files are added
– neckTwi
Nov 13 '18 at 13:04
Copy here all lines of your commands, please. Thegit merge branch1
have to be typed when you are in the branch2 (by thecheckout
command). In the branch1 it's normal to getalready up to date
.
– phili_b
Nov 13 '18 at 13:09
when I'm inbranch2
i didgit checkout -b branch3
and then didgit merge branch1
. butgit ls-files
show files only frombranch2
no files frombranch1
are present.
– neckTwi
Nov 13 '18 at 13:14
now I didgit checkout branch1
andgit merge branch2
. now,git ls-files
don't havebranch1
files!!
– neckTwi
Nov 13 '18 at 13:32
Before each checkout or merge you have to commit. Install TortoiseGit and look at its git commands.
– phili_b
Nov 13 '18 at 20:27
|
show 2 more comments
git merge branch1
just saysalready up to date
but nobranch1
files are added
– neckTwi
Nov 13 '18 at 13:04
Copy here all lines of your commands, please. Thegit merge branch1
have to be typed when you are in the branch2 (by thecheckout
command). In the branch1 it's normal to getalready up to date
.
– phili_b
Nov 13 '18 at 13:09
when I'm inbranch2
i didgit checkout -b branch3
and then didgit merge branch1
. butgit ls-files
show files only frombranch2
no files frombranch1
are present.
– neckTwi
Nov 13 '18 at 13:14
now I didgit checkout branch1
andgit merge branch2
. now,git ls-files
don't havebranch1
files!!
– neckTwi
Nov 13 '18 at 13:32
Before each checkout or merge you have to commit. Install TortoiseGit and look at its git commands.
– phili_b
Nov 13 '18 at 20:27
git merge branch1
just says already up to date
but no branch1
files are added– neckTwi
Nov 13 '18 at 13:04
git merge branch1
just says already up to date
but no branch1
files are added– neckTwi
Nov 13 '18 at 13:04
Copy here all lines of your commands, please. The
git merge branch1
have to be typed when you are in the branch2 (by the checkout
command). In the branch1 it's normal to get already up to date
.– phili_b
Nov 13 '18 at 13:09
Copy here all lines of your commands, please. The
git merge branch1
have to be typed when you are in the branch2 (by the checkout
command). In the branch1 it's normal to get already up to date
.– phili_b
Nov 13 '18 at 13:09
when I'm in
branch2
i did git checkout -b branch3
and then did git merge branch1
. but git ls-files
show files only from branch2
no files from branch1
are present.– neckTwi
Nov 13 '18 at 13:14
when I'm in
branch2
i did git checkout -b branch3
and then did git merge branch1
. but git ls-files
show files only from branch2
no files from branch1
are present.– neckTwi
Nov 13 '18 at 13:14
now I did
git checkout branch1
and git merge branch2
. now, git ls-files
don't have branch1
files!!– neckTwi
Nov 13 '18 at 13:32
now I did
git checkout branch1
and git merge branch2
. now, git ls-files
don't have branch1
files!!– neckTwi
Nov 13 '18 at 13:32
Before each checkout or merge you have to commit. Install TortoiseGit and look at its git commands.
– phili_b
Nov 13 '18 at 20:27
Before each checkout or merge you have to commit. Install TortoiseGit and look at its git commands.
– phili_b
Nov 13 '18 at 20:27
|
show 2 more comments
There isn't an easy way to do what you're describing, because it runs against the grain of git branches.
Branches in git are meant for tracking different lines of evolution of the same content. This isn't to say that it's the only possible use - git is very flexible - but that is the intent, and anything else may or may not be easy to do.
And in particular, switching back and forth between branches that contain different content, to keep the combined content on the work tree, is not something that's easy to do[1].
I recommend you take a step back and look at why you want one branch to have the password files, and another branch to have the boot directory and fstab. Understanding what problem you're trying to solve there, we might be able to suggest an alternative solution to that problem so that you can use git more in tune with its design.
At a bare minimum, to make what you're doing "work" (and I put "work" in quotes, because it's likely to have some quirky side-effects), you would probably want to:
- On each branch, add the files excluded from that branch to
.gitignore
- Before switching to a branch that includes files not on the current branch, you may have to remove the working copies of those files. (In the simple two-branch example, you might do this with
git clean -x
, but be aware this would also sweep up any other ignored working tree files - such as build artifacts that would then have to be regenerated.) - After switching to a branch that excludes files on the current branch, check those files out from the current branch (
git checkout HEAD@1 -- ets/fstab
and so on)
Honestly that doesn't sound like much fun for a "might work basically correctly most of the time" solution, which is why I recommend instead looking at why you have different files on different branches.
[1] That may seem weird, if you are used to tools that do use branches in that way. But if you look at the general case of branches as defined by git, you will realize there are good reasons why it doesn't want to make assumptions that would make this "easy".
I didn't read your answer initially because I didn't understand your lines:because it runs against the grain of git branches
,lines of evolution
. too dramatic you see? But after I've put my answer I've become curious to understand what you are trying to say; You said the same!
– neckTwi
Nov 14 '18 at 3:57
@neckTwi - No, in fact I don't see. There is nothing "dramatic" about those phrases, and they are pretty standard in expressing what I'm saying. Also, our answers definitely do not say the same thing, and in fact I think you might want to spend a little time better understanding git's branch model - because, for example, to say that branches have "ancestors" in git is incorrect.
– Mark Adelsberger
Nov 15 '18 at 0:43
I've corrected my phrase merging an ancestor has no effect. since a new branch being checked out have the same history as the current branch, doesn't it make the current branch an ancestor to the new branch?
– neckTwi
Nov 15 '18 at 16:57
@neckTwi : No. I wonder if I'm somehow not understanding your question, because it looks as though you just asked me whether something is true, that I had literally just said is not true...
– Mark Adelsberger
Nov 15 '18 at 18:23
add a comment |
There isn't an easy way to do what you're describing, because it runs against the grain of git branches.
Branches in git are meant for tracking different lines of evolution of the same content. This isn't to say that it's the only possible use - git is very flexible - but that is the intent, and anything else may or may not be easy to do.
And in particular, switching back and forth between branches that contain different content, to keep the combined content on the work tree, is not something that's easy to do[1].
I recommend you take a step back and look at why you want one branch to have the password files, and another branch to have the boot directory and fstab. Understanding what problem you're trying to solve there, we might be able to suggest an alternative solution to that problem so that you can use git more in tune with its design.
At a bare minimum, to make what you're doing "work" (and I put "work" in quotes, because it's likely to have some quirky side-effects), you would probably want to:
- On each branch, add the files excluded from that branch to
.gitignore
- Before switching to a branch that includes files not on the current branch, you may have to remove the working copies of those files. (In the simple two-branch example, you might do this with
git clean -x
, but be aware this would also sweep up any other ignored working tree files - such as build artifacts that would then have to be regenerated.) - After switching to a branch that excludes files on the current branch, check those files out from the current branch (
git checkout HEAD@1 -- ets/fstab
and so on)
Honestly that doesn't sound like much fun for a "might work basically correctly most of the time" solution, which is why I recommend instead looking at why you have different files on different branches.
[1] That may seem weird, if you are used to tools that do use branches in that way. But if you look at the general case of branches as defined by git, you will realize there are good reasons why it doesn't want to make assumptions that would make this "easy".
I didn't read your answer initially because I didn't understand your lines:because it runs against the grain of git branches
,lines of evolution
. too dramatic you see? But after I've put my answer I've become curious to understand what you are trying to say; You said the same!
– neckTwi
Nov 14 '18 at 3:57
@neckTwi - No, in fact I don't see. There is nothing "dramatic" about those phrases, and they are pretty standard in expressing what I'm saying. Also, our answers definitely do not say the same thing, and in fact I think you might want to spend a little time better understanding git's branch model - because, for example, to say that branches have "ancestors" in git is incorrect.
– Mark Adelsberger
Nov 15 '18 at 0:43
I've corrected my phrase merging an ancestor has no effect. since a new branch being checked out have the same history as the current branch, doesn't it make the current branch an ancestor to the new branch?
– neckTwi
Nov 15 '18 at 16:57
@neckTwi : No. I wonder if I'm somehow not understanding your question, because it looks as though you just asked me whether something is true, that I had literally just said is not true...
– Mark Adelsberger
Nov 15 '18 at 18:23
add a comment |
There isn't an easy way to do what you're describing, because it runs against the grain of git branches.
Branches in git are meant for tracking different lines of evolution of the same content. This isn't to say that it's the only possible use - git is very flexible - but that is the intent, and anything else may or may not be easy to do.
And in particular, switching back and forth between branches that contain different content, to keep the combined content on the work tree, is not something that's easy to do[1].
I recommend you take a step back and look at why you want one branch to have the password files, and another branch to have the boot directory and fstab. Understanding what problem you're trying to solve there, we might be able to suggest an alternative solution to that problem so that you can use git more in tune with its design.
At a bare minimum, to make what you're doing "work" (and I put "work" in quotes, because it's likely to have some quirky side-effects), you would probably want to:
- On each branch, add the files excluded from that branch to
.gitignore
- Before switching to a branch that includes files not on the current branch, you may have to remove the working copies of those files. (In the simple two-branch example, you might do this with
git clean -x
, but be aware this would also sweep up any other ignored working tree files - such as build artifacts that would then have to be regenerated.) - After switching to a branch that excludes files on the current branch, check those files out from the current branch (
git checkout HEAD@1 -- ets/fstab
and so on)
Honestly that doesn't sound like much fun for a "might work basically correctly most of the time" solution, which is why I recommend instead looking at why you have different files on different branches.
[1] That may seem weird, if you are used to tools that do use branches in that way. But if you look at the general case of branches as defined by git, you will realize there are good reasons why it doesn't want to make assumptions that would make this "easy".
There isn't an easy way to do what you're describing, because it runs against the grain of git branches.
Branches in git are meant for tracking different lines of evolution of the same content. This isn't to say that it's the only possible use - git is very flexible - but that is the intent, and anything else may or may not be easy to do.
And in particular, switching back and forth between branches that contain different content, to keep the combined content on the work tree, is not something that's easy to do[1].
I recommend you take a step back and look at why you want one branch to have the password files, and another branch to have the boot directory and fstab. Understanding what problem you're trying to solve there, we might be able to suggest an alternative solution to that problem so that you can use git more in tune with its design.
At a bare minimum, to make what you're doing "work" (and I put "work" in quotes, because it's likely to have some quirky side-effects), you would probably want to:
- On each branch, add the files excluded from that branch to
.gitignore
- Before switching to a branch that includes files not on the current branch, you may have to remove the working copies of those files. (In the simple two-branch example, you might do this with
git clean -x
, but be aware this would also sweep up any other ignored working tree files - such as build artifacts that would then have to be regenerated.) - After switching to a branch that excludes files on the current branch, check those files out from the current branch (
git checkout HEAD@1 -- ets/fstab
and so on)
Honestly that doesn't sound like much fun for a "might work basically correctly most of the time" solution, which is why I recommend instead looking at why you have different files on different branches.
[1] That may seem weird, if you are used to tools that do use branches in that way. But if you look at the general case of branches as defined by git, you will realize there are good reasons why it doesn't want to make assumptions that would make this "easy".
answered Nov 13 '18 at 16:51
Mark AdelsbergerMark Adelsberger
21.1k11321
21.1k11321
I didn't read your answer initially because I didn't understand your lines:because it runs against the grain of git branches
,lines of evolution
. too dramatic you see? But after I've put my answer I've become curious to understand what you are trying to say; You said the same!
– neckTwi
Nov 14 '18 at 3:57
@neckTwi - No, in fact I don't see. There is nothing "dramatic" about those phrases, and they are pretty standard in expressing what I'm saying. Also, our answers definitely do not say the same thing, and in fact I think you might want to spend a little time better understanding git's branch model - because, for example, to say that branches have "ancestors" in git is incorrect.
– Mark Adelsberger
Nov 15 '18 at 0:43
I've corrected my phrase merging an ancestor has no effect. since a new branch being checked out have the same history as the current branch, doesn't it make the current branch an ancestor to the new branch?
– neckTwi
Nov 15 '18 at 16:57
@neckTwi : No. I wonder if I'm somehow not understanding your question, because it looks as though you just asked me whether something is true, that I had literally just said is not true...
– Mark Adelsberger
Nov 15 '18 at 18:23
add a comment |
I didn't read your answer initially because I didn't understand your lines:because it runs against the grain of git branches
,lines of evolution
. too dramatic you see? But after I've put my answer I've become curious to understand what you are trying to say; You said the same!
– neckTwi
Nov 14 '18 at 3:57
@neckTwi - No, in fact I don't see. There is nothing "dramatic" about those phrases, and they are pretty standard in expressing what I'm saying. Also, our answers definitely do not say the same thing, and in fact I think you might want to spend a little time better understanding git's branch model - because, for example, to say that branches have "ancestors" in git is incorrect.
– Mark Adelsberger
Nov 15 '18 at 0:43
I've corrected my phrase merging an ancestor has no effect. since a new branch being checked out have the same history as the current branch, doesn't it make the current branch an ancestor to the new branch?
– neckTwi
Nov 15 '18 at 16:57
@neckTwi : No. I wonder if I'm somehow not understanding your question, because it looks as though you just asked me whether something is true, that I had literally just said is not true...
– Mark Adelsberger
Nov 15 '18 at 18:23
I didn't read your answer initially because I didn't understand your lines:
because it runs against the grain of git branches
, lines of evolution
. too dramatic you see? But after I've put my answer I've become curious to understand what you are trying to say; You said the same!– neckTwi
Nov 14 '18 at 3:57
I didn't read your answer initially because I didn't understand your lines:
because it runs against the grain of git branches
, lines of evolution
. too dramatic you see? But after I've put my answer I've become curious to understand what you are trying to say; You said the same!– neckTwi
Nov 14 '18 at 3:57
@neckTwi - No, in fact I don't see. There is nothing "dramatic" about those phrases, and they are pretty standard in expressing what I'm saying. Also, our answers definitely do not say the same thing, and in fact I think you might want to spend a little time better understanding git's branch model - because, for example, to say that branches have "ancestors" in git is incorrect.
– Mark Adelsberger
Nov 15 '18 at 0:43
@neckTwi - No, in fact I don't see. There is nothing "dramatic" about those phrases, and they are pretty standard in expressing what I'm saying. Also, our answers definitely do not say the same thing, and in fact I think you might want to spend a little time better understanding git's branch model - because, for example, to say that branches have "ancestors" in git is incorrect.
– Mark Adelsberger
Nov 15 '18 at 0:43
I've corrected my phrase merging an ancestor has no effect. since a new branch being checked out have the same history as the current branch, doesn't it make the current branch an ancestor to the new branch?
– neckTwi
Nov 15 '18 at 16:57
I've corrected my phrase merging an ancestor has no effect. since a new branch being checked out have the same history as the current branch, doesn't it make the current branch an ancestor to the new branch?
– neckTwi
Nov 15 '18 at 16:57
@neckTwi : No. I wonder if I'm somehow not understanding your question, because it looks as though you just asked me whether something is true, that I had literally just said is not true...
– Mark Adelsberger
Nov 15 '18 at 18:23
@neckTwi : No. I wonder if I'm somehow not understanding your question, because it looks as though you just asked me whether something is true, that I had literally just said is not true...
– Mark Adelsberger
Nov 15 '18 at 18:23
add a comment |
Understand how Git works!
By default, every Git branch has an ancestor except the initial master branch which is an ancestor to all other branches. So if any branch has only exclusive files than any other branch then you should have deleted all the files from the branch initially and added some exclusive files to it.
So if the branch1
is an ancestor to branch2
and branch2
don't have the files of branch1
then branch2
is marked to not contain files of branch1
. So merging branch1
to branch2
will remove the files of branch1
in branch2
. Yes, merging an ancestor has no effect other than updating the changes of the ancestor.
Though one can git checkout --orphan NewOrphan
, It can't be merged with another branch with a different history (ancestor).
So the only way to do it is as @EugenConstantinDinca said in the comment. Or rethink what you are trying to achieve by not removing the files of the parent branch.
add a comment |
Understand how Git works!
By default, every Git branch has an ancestor except the initial master branch which is an ancestor to all other branches. So if any branch has only exclusive files than any other branch then you should have deleted all the files from the branch initially and added some exclusive files to it.
So if the branch1
is an ancestor to branch2
and branch2
don't have the files of branch1
then branch2
is marked to not contain files of branch1
. So merging branch1
to branch2
will remove the files of branch1
in branch2
. Yes, merging an ancestor has no effect other than updating the changes of the ancestor.
Though one can git checkout --orphan NewOrphan
, It can't be merged with another branch with a different history (ancestor).
So the only way to do it is as @EugenConstantinDinca said in the comment. Or rethink what you are trying to achieve by not removing the files of the parent branch.
add a comment |
Understand how Git works!
By default, every Git branch has an ancestor except the initial master branch which is an ancestor to all other branches. So if any branch has only exclusive files than any other branch then you should have deleted all the files from the branch initially and added some exclusive files to it.
So if the branch1
is an ancestor to branch2
and branch2
don't have the files of branch1
then branch2
is marked to not contain files of branch1
. So merging branch1
to branch2
will remove the files of branch1
in branch2
. Yes, merging an ancestor has no effect other than updating the changes of the ancestor.
Though one can git checkout --orphan NewOrphan
, It can't be merged with another branch with a different history (ancestor).
So the only way to do it is as @EugenConstantinDinca said in the comment. Or rethink what you are trying to achieve by not removing the files of the parent branch.
Understand how Git works!
By default, every Git branch has an ancestor except the initial master branch which is an ancestor to all other branches. So if any branch has only exclusive files than any other branch then you should have deleted all the files from the branch initially and added some exclusive files to it.
So if the branch1
is an ancestor to branch2
and branch2
don't have the files of branch1
then branch2
is marked to not contain files of branch1
. So merging branch1
to branch2
will remove the files of branch1
in branch2
. Yes, merging an ancestor has no effect other than updating the changes of the ancestor.
Though one can git checkout --orphan NewOrphan
, It can't be merged with another branch with a different history (ancestor).
So the only way to do it is as @EugenConstantinDinca said in the comment. Or rethink what you are trying to achieve by not removing the files of the parent branch.
edited Nov 15 '18 at 16:35
answered Nov 14 '18 at 3:33
neckTwineckTwi
82751740
82751740
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53281029%2fgit-how-to-checkout-without-removing-exclusive-files-from-current-branch%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Should probably just merge the 2 branches (maybe onto a third one). Otherwise something based off
git diff -p branch1..branch2 | patch
should work (am assuming your OS/toolkit has apatch
and so forth).– Eugen Constantin Dinca
Nov 13 '18 at 12:43