git-checkout

Difference between git checkout --track origin/branch and git checkout -b branch origin/branch

南楼画角 提交于 2019-11-26 01:52:21
问题 Does anybody know the difference between these two commands to switch and track a remote branch? git checkout -b branch origin/branch git checkout --track origin/branch I think both keep track of the remote branch so I can push my changes to the branch on origin, right? Is there any practical differences?? Thanks! 回答1: The two commands have the same effect (thanks to Robert Siemer’s answer for pointing it out). The practical difference comes when using a local branch named differently : git

How to get just one file from another branch

时间秒杀一切 提交于 2019-11-26 01:40:35
问题 I am using git and working on master branch. This branch has a file called app.js . I have an experiment branch in which I made a bunch of changes and tons of commits. Now I want to bring all the changes done only to app.js from experiment to master branch. How do I do that? Once again I do not want a merge. I just want to bring all the changes in app.js from experiment branch to master branch. 回答1: git checkout master # first get back to master git checkout experiment -- app.js # then copy

Meaning of Git checkout double dashes

删除回忆录丶 提交于 2019-11-26 01:03:54
问题 What is the meaning of the double dashes before the file name in this git command? git checkout --ours -- path/to/file.txt git checkout --theirs -- path/to/file.txt Are they mandatory? Is it equivalent to git checkout --ours path/to/file.txt git checkout --theirs path/to/file.txt 回答1: Suppose I have a file named path/to/file.txt in my Git repository, and I want to revert changes on it. git checkout path/to/file.txt Now suppose that the file is named master ... git checkout master Whoops! That

What's the difference between “git reset” and “git checkout”?

喜你入骨 提交于 2019-11-26 00:44:50
问题 I\'ve always thought of git reset and git checkout as the same, in the sense that both bring the project back to a specific commit. However, I feel they can\'t be exactly the same, as that would be redundant. What is the actual difference between the two? I\'m a bit confused, as the svn only has svn co to revert the commit. ADDED VonC and Charles explained the differences between git reset and git checkout really well. My current understanding is that git reset reverts all of the changes back

How to get the latest tag name in current branch in Git?

送分小仙女□ 提交于 2019-11-26 00:35:35
问题 What\'s the simplest way to get the most recent tag in Git? git tag a HEAD git tag b HEAD^^ git tag c HEAD^ git tag output: a b c Should I write a script to get each tag\'s datetime and compare them? 回答1: You could take a look at git describe , which does something close to what you're asking. 回答2: To get the most recent tag: git describe --tags To get the most recent annotated tag: git describe --abbrev=0 回答3: Will output the tag of the latest tagged commit across all branches git describe -

How do I check out a remote Git branch?

痴心易碎 提交于 2019-11-25 23:58:23
问题 Somebody pushed a branch called test with git push origin test to a shared repository. I can see the branch with git branch -r . Now I\'m trying to check out the remote test branch. I\'ve tried: git checkout test which does nothing git checkout origin/test gives * (no branch) . Which is confusing. How can I be on \"no branch\"? How do I check out a remote Git branch? 回答1: Update Jakub's answer actually improves on this. With Git versions ≥ 1.6.6, with only one remote, you can just do: git

Merge, update, and pull Git branches without using checkouts

你离开我真会死。 提交于 2019-11-25 23:26:07
问题 I work on a project that has 2 branches, A and B. I typically work on branch A, and merge stuff from branch B. For the merging, I would typically do: git merge origin/branchB However, I would also like to keep a local copy of branch B, as I may occasionally check out the branch without first merging with my branch A. For this, I would do: git checkout branchB git pull git checkout branchA Is there a way to do the above in one command, and without having to switch branch back and forth? Should

How can I reset or revert a file to a specific revision?

佐手、 提交于 2019-11-25 22:19:52
问题 I have made some changes to a file which has been committed a few times as part of a group of files, but now want to reset/revert the changes on it back to a previous version. I have done a git log along with a git diff to find the revision I need, but just have no idea how to get the file back to its former state in the past. 回答1: Assuming the hash of the commit you want is c5f567 : git checkout c5f567 -- file1/to/restore file2/to/restore The git checkout man page gives more information. If

How to move HEAD back to a previous location? (Detached head) & Undo commits

荒凉一梦 提交于 2019-11-25 22:13:45
问题 In git, I was trying to do a squash commit by merging in another branch and then resetting HEAD to the previous place via: git reset origin/master But I need to step out of this. How can I move HEAD back to the previous location? I have the SHA1 frag ( 23b6772 ) of the commit that I need to move it to. How can I get back to this commit? 回答1: Before answering let's add some background, explaining what is this HEAD . First of all what is HEAD? HEAD is simply a reference to the current commit

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

删除回忆录丶 提交于 2019-11-25 21:34:41
问题 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 <me@me.com> Date: Thu Nov 4 18:59:41 2010 -0400 blah blah blah... commit 25eee4caef46ae64aa08e8ab3f988bc917ee1ce4 Author: Me <me@me.com> Date: Thu Nov 4 05:13:39 2010 -0400 more blah blah blah... commit 0766c053c0ea2035e90f504928f8df3c9363b8bd Author: Me <me@me.com> Date: Thu Nov 4 00:55:06 2010