git-checkout

How can I get a list of Git branches that I've recently checked out?

佐手、 提交于 2019-12-03 08:30:08
问题 When moving between Git branches I sometimes forget the name of a branch I was recently on. How can I display a list of recently checked out branches/tags/commits? 回答1: Summary: You can use Git's reflog to show recent movements: git reflog Script: Here's a script you can download and use via git recent from inside any Git repository: https://gist.github.com/jordan-brough/48e2803c0ffa6dc2e0bd Details: Here's essentially what the script does to make the reflog output more usable: $ git reflog |

How to switch android version in local repo?

痴心易碎 提交于 2019-12-03 05:55:16
问题 I have downloaded whole working tree with the following command: repo init -u https://android.googlesource.com/platform/manifest repo sync -j8 After syncing successfully, I want to switch working tree to android 2.3.7. You see I didn't specify branch with "-b" parameter when "repo init". So I guess all tag info should be downloaded and I can easily switch to android 2.3.7 with the following command: repo forall -c git checkout android-2.3.7_r1 But it produces many errors like: error: pathspec

Are there different meanings to the concept of 'tracking' in git?

一世执手 提交于 2019-12-03 05:44:50
I run 'git branch -r' and get origin/branch1 origin/branch2 From the man page, the -r option will "list or delete (if used with -d) the remote-tracking branches". So origin/branch1 and origin/branch2 are known as remote-tracking branches. However, you can't commit directly onto a remote-tracking branch (an anonymous branch will be created instead). A remote-tracking branch simply tracks a remote branch when running 'git fetch'. Here's where the semantics get a little blurry for me. If I then git checkout -b branch1 origin/branch1 I get the following output: "Branch branch1 set up to track

Git: Checkout all files except one

纵然是瞬间 提交于 2019-12-03 04:42:33
问题 When I do a git status, I see files like this: modified: dir/A/file.txt modified: dir/B/file.txt modified: dir/C/file.txt modified: dir/D/file.txt What I want to do is to discard changes to all files EXCEPT for dir/C/file.txt I want to do something like this: git checkout -- dir/!C/file.txt 回答1: git add dir/C/file.txt # this file will stay modified and staged git checkout . If you want to unstage the file after that: git reset 来源: https://stackoverflow.com/questions/20008025/git-checkout-all

Is it possible to view multiple git branches at the same time for the same project?

有些话、适合烂在心里 提交于 2019-12-03 03:24:59
问题 I have 2 branches, which are not ready to be merged yet, but have some complementary logic, which I'd like to review (before merging) Can I check out multiple git branches of the same project? Is it possible? 回答1: You can simply copy the repository to a new location (either by literally copying the directory, or using git clone --shared) and check out one branch per location. You can also use git-worktree for creating multiple working directories from a single instance of a repository.

Fetch a single tag from remote repository

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 01:46:46
This command fetches all tags: git fetch origin --tags This command fetches a specific tag: git fetch origin refs/tags/1.0.0 But that doesn't let me do: git checkout tags/2.3.18 How can I fetch a single tag and then perform a checkout? git fetch origin refs/tags/1.0.0 This fails because it doesn't write a local reference: it obtains the remote's refs/tags/1.0.0 , and any tag object(s), commits, etc., required to go with it; it drops those into FETCH_HEAD (as all git fetch commands always do); and ... that's it. It never creates reference refs/tags/1.0.0 in your repository, even though it got

git - getting ALL previous version of a specific file/folder

岁酱吖の 提交于 2019-12-03 00:25:38
I want to retrieve all previous version of a specific file in a git repository. I see it is possible to get one specific version with the checkout command, but I want them all. And the git clone command with the depth option doesn't seem to allow me to clone subfolder ("not valid repository name"). Do you know if it is possible and how? Thank you OP wanted to retrieve all versions, but the answers would not deliver. Especially if the file has hundreds of revisions (all suggestions are too manual). The only half-working solution was proposed by @Tobias in the comments, but suggested bash loop

Git pushd & popd? I.e., checkout last state

爷,独闯天下 提交于 2019-12-02 23:23:23
I'm writing a Bash script, and I want to checkout a tag and then checkout back to where I started. I tried git co HEAD@{1} , but when starting at master, that takes me back to the commit SHA of master but with a detatched head. Is there something like pushd & popd for Git? git checkout @{-1} which can be abbreviated to git checkout - . From the manpage: As a special case, the "@{-N}" syntax for the N-th last branch checks out the branch (instead of detaching). You may also specify - which is synonymous with "@{-1}". EDIT: wnoise's suggestion will work if you don't want to keep an explicit

How can I get a list of Git branches that I've recently checked out?

蓝咒 提交于 2019-12-02 22:15:38
When moving between Git branches I sometimes forget the name of a branch I was recently on. How can I display a list of recently checked out branches/tags/commits? Jordan Brough Summary: You can use Git's reflog to show recent movements: git reflog Script: Here's a script you can download and use via git recent from inside any Git repository: https://gist.github.com/jordan-brough/48e2803c0ffa6dc2e0bd Details: Here's essentially what the script does to make the reflog output more usable: $ git reflog | egrep -io "moving from ([^[:space:]]+)" | awk '{ print $3 }' | awk ' !x[$0]++' | egrep -v '^

GIT checkout except one folder

杀马特。学长 韩版系。学妹 提交于 2019-12-02 20:54:51
I want to checkout to other branch, or previous commit, but I want to keep one folder the same files (not checkout the folder). I want that the folder, will be shown in git status , so I can add this folder now to the index. For example, I have a folder with node_modules . I want the folder to be in all my commits (I know that most of the people prefer to .gitignore the node_modules folder). But when I move to other commit, or checkut other branch, I want that git will not touch the node_modules folder. Is it possible? You could use sparse checkout to exclude the committed contents of the node