Questions tagged [clone]

A clone is a copy of an object with all of the same attributes, data, and methods as the original object. Or a software system that is designed to mimic another system.

A clone is a copy of an object with all of the same attributes, data, and methods as the original.

In practice, an object is cloned when you want to duplicate the original exactly and then change it in some way, such as changing a due date on a recurring task or linking it to a different object in a database hierarchy.

In computing, a clone is a hardware or software system that is designed to mimic another system.

See Also:

4519 questions
5169
votes
67 answers

What is the most efficient way to deep clone an object in JavaScript?

What is the most efficient way to clone a JavaScript object? I've seen obj = eval(uneval(o)); being used, but that's non-standard and only supported by Firefox. I've done things like obj = JSON.parse(JSON.stringify(o)); but question the efficiency. …
jschrab
  • 11,035
  • 4
  • 20
  • 17
3701
votes
81 answers

How do I correctly clone a JavaScript object?

I have an object x. I'd like to copy it as object y, such that changes to y do not modify x. I realized that copying objects derived from built-in JavaScript objects will result in extra, unwanted properties. This isn't a problem, since I'm copying…
soundly_typed
  • 39,257
  • 5
  • 28
  • 36
2611
votes
59 answers

Deep cloning objects

I want to do something like: MyObject myObj = GetMyObj(); // Create and fill a new object MyObject newObj = myObj.Clone(); And then make changes to the new object that are not reflected in the original object. I don't often need this functionality,…
NakedBrunch
  • 48,713
  • 13
  • 73
  • 98
1371
votes
9 answers

How to rebase local branch onto remote master

I have a cloned project from a master branch from remote repository remote_repo. I create a new branch and I commit to that branch. Other programmers pushed to remote_repo to the master branch. I now need to rebase my local branch RB onto…
Damir
  • 54,277
  • 94
  • 246
  • 365
914
votes
23 answers

How do I copy an object in Java?

Consider the code below: DummyBean dum = new DummyBean(); dum.setDummy("foo"); System.out.println(dum.getDummy()); // prints 'foo' DummyBean dumtwo = dum; System.out.println(dumtwo.getDummy()); // prints…
Veera
  • 32,532
  • 36
  • 98
  • 137
744
votes
29 answers

How do I clone a generic list in C#?

I have a generic list of objects in C#, and wish to clone the list. The items within the list are cloneable, but there doesn't seem to be an option to do list.Clone(). Is there an easy way around this?
Fiona
  • 7,747
  • 4
  • 19
  • 8
687
votes
10 answers

How do you do a deep copy of an object in .NET?

I want a true deep copy. In Java, this was easy, but how do you do it in C#?
user18931
  • 10,715
  • 9
  • 28
  • 21
518
votes
5 answers

What are the differences between git branch, fork, fetch, merge, rebase and clone?

I want to understand the difference between a branch, a fork and a clone in Git? Similarly, what does it mean when I do a git fetch as opposed to a git pull? Also, what does rebase mean in comparison to merge? How can I squash individual commits…
jackiekazil
  • 5,696
  • 4
  • 21
  • 20
384
votes
26 answers

How do I clone a range of array elements to a new array?

I have an array X of 10 elements. I would like to create a new array containing all the elements from X that begin at index 3 and ends in index 7. Sure I can easily write a loop that will do it for me but I would like to keep my code as clean as…
user88637
  • 11,790
  • 9
  • 37
  • 36
378
votes
7 answers

How to convert a Git shallow clone to a full clone?

Follow-up of this so-question: if I have a shallow clone, how to fetch all older commits to make it a full clone?
Mot
  • 28,248
  • 23
  • 84
  • 121
360
votes
21 answers

How do you make a deep copy of an object?

It's a bit difficult to implement a deep object copy function. What steps you take to ensure the original object and the cloned one share no reference?
Andrei Savu
  • 8,525
  • 7
  • 46
  • 53
328
votes
12 answers

What is the difference between pull and clone in git?

What is the difference between doing (after mkdir repo and cd repo): git init git remote add origin git://github.com/cmcculloh/repo.git git fetch --all git pull origin master and git clone git://github.com/cmcculloh/repo.git I mean, obviously one…
cmcculloh
  • 47,596
  • 40
  • 105
  • 130
312
votes
20 answers

git: fatal: I don't handle protocol '​​http'

I copy and pasted an git clone command from a web page: https://fedorahosted.org/ibus-typing-booster/ I got this: user@host> git clone ​​http://git.fedorahosted.org/git/ibus-typing-booster.git Cloning into 'ibus-typing-booster'... fatal: I don't…
guettli
  • 25,042
  • 81
  • 346
  • 663
308
votes
21 answers

How to clone ArrayList and also clone its contents?

How can I clone an ArrayList and also clone its items in Java? For example I have: ArrayList dogs = getDogs(); ArrayList clonedList = ....something to do with dogs.... And I would expect that objects in clonedList are not the same as in…
palig
  • 7,651
  • 6
  • 24
  • 18
273
votes
14 answers

What is the best way to clone/deep copy a .NET generic Dictionary?

I've got a generic dictionary Dictionary that I would like to essentially make a Clone() of ..any suggestions.
mikeymo
  • 3,145
  • 3
  • 23
  • 16
1
2 3
99 100