Most Popular

1500 questions
8468
votes
43 answers

How do I check out a remote Git branch?

Somebody pushed a branch called test with git push origin test to a shared repository. I can see the branch with git branch -r. How do I check out the remote test branch? I've tried: git checkout test, which does nothing git checkout origin/test…
Juri Glass
  • 88,173
  • 8
  • 33
  • 46
8421
votes
31 answers

What does "use strict" do in JavaScript, and what is the reasoning behind it?

Recently, I ran some of my JavaScript code through Crockford's JSLint, and it gave the following error: Problem at line 1 character 1: Missing "use strict" statement. Doing some searching, I realized that some people add "use strict"; into their…
Mark Rogers
  • 96,497
  • 18
  • 85
  • 138
8066
votes
46 answers

What does if __name__ == "__main__": do?

What does this do, and why should one include the if statement? if __name__ == "__main__": print("Hello, World!") If you are trying to close a question where someone should be using this idiom and isn't, consider closing as a duplicate of Why…
Devoted
  • 177,705
  • 43
  • 90
  • 110
8004
votes
41 answers

How do I remove local (untracked) files from the current Git working tree?

How do I delete untracked local files from the current working tree?
readonly
  • 343,444
  • 107
  • 203
  • 205
7951
votes
33 answers

How do I make Git forget about a file that was tracked, but is now in .gitignore?

I put a file that was previously being tracked by Git onto the .gitignore list. However, the file still shows up in git status after it is edited. How do I force Git to completely forget the file?
Ivan
  • 97,549
  • 17
  • 50
  • 58
7779
votes
32 answers

Does Python have a ternary conditional operator?

Is there a ternary conditional operator in Python?
Devoted
  • 177,705
  • 43
  • 90
  • 110
7724
votes
91 answers

Is Java "pass-by-reference" or "pass-by-value"?

I always thought Java uses pass-by-reference. However, I read a blog post which claims that Java uses pass-by-value. I don't think I understand the distinction the author is making. What is the explanation?
user4315
  • 4,775
  • 5
  • 23
  • 9
7703
votes
58 answers

How do I redirect to another webpage?

How can I redirect the user from one page to another using jQuery or pure JavaScript?
venkatachalam
  • 102,353
  • 31
  • 72
  • 77
7650
votes
27 answers

How to modify existing, unpushed commit messages?

I wrote the wrong thing in a commit message. How can I change the message? The commit has not been pushed yet.
Laurie Young
  • 136,234
  • 13
  • 47
  • 54
7621
votes
86 answers

How do JavaScript closures work?

How would you explain JavaScript closures to someone with a knowledge of the concepts they consist of (for example functions, variables and the like), but does not understand closures themselves? I have seen the Scheme example given on Wikipedia,…
Bite code
  • 578,959
  • 113
  • 301
  • 329
7611
votes
41 answers

How do I revert a Git repository to a previous commit?

How do I revert from my current state to a snapshot made on a certain commit? If I do git log, then I get the following output: $ git log commit a867b4af366350be2e7c21b8de9cc6504678a61b` Author: Me Date: Thu Nov 4 18:59:41 2010…
Crazy Serb
  • 76,330
  • 8
  • 35
  • 47
7585
votes
41 answers

var functionName = function() {} vs function functionName() {}

I've recently started maintaining someone else's JavaScript code. I'm fixing bugs, adding features and also trying to tidy up the code and make it more consistent. The previous developer used two ways of declaring functions and I can't work out if…
Richard Garside
  • 87,839
  • 11
  • 80
  • 93
7506
votes
10 answers

Why is subtracting these two epoch-milli Times (in year 1927) giving a strange result?

If I run the following program, which parses two date strings referencing times 1 second apart and compares them: public static void main(String[] args) throws ParseException { SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); …
Freewind
  • 193,756
  • 157
  • 432
  • 708
7486
votes
66 answers

What is the difference between String and string in C#?

What are the differences between these two, and which one should I use? string s = "Hello world!"; String s = "Hello world!";
Lance Fisher
  • 25,684
  • 22
  • 96
  • 122
7407
votes
3 answers

How to check whether a string contains a substring in JavaScript?

Usually I would expect a String.contains() method, but there doesn't seem to be one. What is a reasonable way to check for this?
gramm
  • 18,786
  • 7
  • 27
  • 27