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
132
votes
14 answers

"fatal: Not a git repository (or any of the parent directories)" from git status

This command works to get the files and compile them: git clone a-valid-git-url for example: git clone git://cfdem.git.sourceforge.net/gitroot/cfdem/liggghts However, git status (or any other git command) then gives the above fatal: Not a git…
Kevin Kostlan
  • 3,311
  • 7
  • 29
  • 33
130
votes
3 answers

What do these words mean in Git: Repository, fork, branch, clone, track?

I'm honestly not clear on the semantics here. They're all about copies/variants of a code+history unit, but past that I'm not sure I could say. Is this logical structure explained somewhere?
Eric Anderson
  • 1,968
  • 2
  • 15
  • 19
125
votes
9 answers

How to properly override clone method?

I need to implement a deep clone in one of my objects which has no superclass. What is the best way to handle the checked CloneNotSupportedException thrown by the superclass (which is Object)? A coworker advised me to handle it the following…
Cuga
  • 17,668
  • 31
  • 111
  • 166
122
votes
11 answers

Why is the clone() method protected in java.lang.Object?

What is the specific reason that clone() is defined as protected in java.lang.Object?
Alex N.
  • 14,805
  • 10
  • 46
  • 54
119
votes
12 answers

Clone an Eloquent object including all relationships?

Is there any way to easily clone an Eloquent object, including all of its relationships? For example, if I had these tables: users ( id, name, email ) roles ( id, name ) user_roles ( user_id, role_id ) In addition to creating a new row in the users…
andrewtweber
  • 24,520
  • 22
  • 88
  • 110
116
votes
8 answers

Can the owner of a repo see clones?

I know that the owner of a repo is able to see a fork request when one is performed. But what about a clone? Can the owner of the repo see when someone clones it?
goodcow
  • 4,495
  • 6
  • 33
  • 52
112
votes
10 answers

How to clone object in Kotlin?

The Kotlin documentation describes cloning only in accessing Java and in enum class. In latter case clone is just throwing an exception. So, how would I / should I clone arbitrary Kotlin object? Should I just use clone() as in Java?
Dims
  • 47,675
  • 117
  • 331
  • 600
112
votes
3 answers

How can I clone a DateTime object in C#?

How can I clone a DateTime object in C#?
Iain
  • 9,432
  • 11
  • 47
  • 64
111
votes
3 answers

Shallow copy of a Map in Java

As I understand it, there are a couple of ways (maybe others as well) to create a shallow copy of a Map in Java: Map data = new HashMap(); Map shallowCopy; // first way shallowCopy = new…
dcp
  • 54,410
  • 22
  • 144
  • 164
98
votes
2 answers

Clone method for Java arrays

What exactly does the clone() method in Java return when used on an array? Does it return a new array with data copied from the original? Ex: int[] a = {1,2,3}; int[] b = a.clone();
Bunsen McDubbs
  • 1,151
  • 1
  • 9
  • 9
94
votes
11 answers

How create a new deep copy (clone) of a List?

In the following piece of code, using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; namespace clone_test_01 { public partial class MainForm : Form { public class Book { …
TheScholar
  • 2,527
  • 5
  • 23
  • 25
93
votes
4 answers

Does calling clone() on an array also clone its contents?

If I invoke clone() method on array of Objects of type A, how will it clone its elements? Will the copy be referencing to the same objects? Or will it call (element of type A).clone() for each of them?
Szymon
  • 931
  • 1
  • 6
  • 3
86
votes
10 answers

clone() vs copy constructor vs factory method?

I did a quick google on implementing clone() in Java and found: http://www.javapractices.com/topic/TopicAction.do?Id=71 It has the following comment: copy constructors and static factory methods provide an alternative to clone, and are much easier…
User1
  • 39,458
  • 69
  • 187
  • 265
81
votes
4 answers

Git how to clone with SSH key, username

I have the following and i need to clone the repository in either windows terminal command prompt or linux. URL: git@xxxxx.com:xxx/xxx/git username: xxx@xxx.in SSH key: ssh-rsa AAAAB3NzaC1yxxxxxxxxxxxx....xxx@xxx.in I tried as : git clone…
Sushivam
  • 2,537
  • 4
  • 15
  • 25
81
votes
2 answers

What's the difference between Bitmap.Clone() and new Bitmap(Bitmap)?

As far as I can tell, there are two ways of copying a bitmap. Bitmap.Clone() Bitmap A = new Bitmap("somefile.png"); Bitmap B = (Bitmap)A.Clone(); new Bitmap() Bitmap A = new Bitmap("somefile.png"); Bitmap B = new Bitmap(A); How do these approaches…
Tom Wright
  • 11,278
  • 15
  • 74
  • 148